Skip to content

Commit 1805d64

Browse files
committed
Get all pieces ready for action
1 parent 0bcb790 commit 1805d64

File tree

5 files changed

+70
-9
lines changed

5 files changed

+70
-9
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ git-object = { version = "^0.2.0", path = "../git-object" }
2323
git-odb = { version = "0.1.0", path = "../git-odb" }
2424
git-features = { version = "^0.2.0", path = "../git-features" }
2525
anyhow = "1.0.31"
26+
quick-error = { version = "1.2.3", git = "https://github.com/tailhook/quick-error", rev = "aad5701556438218339fba452451ae63a47c31c2" }
2627
bytesize = "1.0.1"
2728
serde_json = { version = "1.0.56", optional = true }

gitoxide-core/src/pack/explode.rs

+49-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::{Context, Result};
22
use git_features::progress::Progress;
3-
use git_odb::pack;
3+
use git_object::{owned, HashKind};
4+
use git_odb::{loose, pack};
5+
use std::io::Read;
46
use std::path::Path;
57

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

57+
use quick_error::quick_error;
58+
59+
quick_error! {
60+
#[derive(Debug)]
61+
enum Error {
62+
Io(err: std::io::Error) {
63+
source(err)
64+
from()
65+
}
66+
Odb(err: loose::db::write::Error) {
67+
source(err)
68+
from()
69+
}
70+
}
71+
}
72+
73+
struct OutputWriter(Option<loose::Db>);
74+
75+
impl git_odb::Write for OutputWriter {
76+
type Error = Error;
77+
78+
fn write_stream(
79+
&self,
80+
kind: git_object::Kind,
81+
size: u64,
82+
from: impl Read,
83+
hash: HashKind,
84+
) -> Result<owned::Id, Self::Error> {
85+
match self.0.as_ref() {
86+
Some(db) => db.write_stream(kind, size, from, hash).map_err(Into::into),
87+
None => git_odb::sink().write_stream(kind, size, from, hash).map_err(Into::into),
88+
}
89+
}
90+
fn write_buf(&self, kind: git_object::Kind, from: &[u8], hash: HashKind) -> Result<owned::Id, Self::Error> {
91+
match self.0.as_ref() {
92+
Some(db) => db.write_buf(kind, from, hash).map_err(Into::into),
93+
None => git_odb::sink().write_buf(kind, from, hash).map_err(Into::into),
94+
}
95+
}
96+
}
97+
5598
pub fn pack_or_pack_index<P>(
56-
path: impl AsRef<Path>,
99+
pack_path: impl AsRef<Path>,
100+
object_path: Option<impl AsRef<Path>>,
57101
_check: SafetyCheck,
58102
_progress: Option<P>,
59103
_delete_pack: bool,
60104
) -> Result<()>
61105
where
62106
P: Progress,
63107
{
64-
let path = path.as_ref();
108+
let path = pack_path.as_ref();
65109
let _bundle = pack::Bundle::at(path).with_context(|| {
66110
format!(
67111
"Could not find .idx or .pack file from given file at '{}'",
68112
path.display()
69113
)
70114
})?;
115+
116+
let _out = OutputWriter(object_path.map(|path| loose::Db::at(path.as_ref())));
71117
Ok(())
72118
}

src/plumbing/lean.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ mod options {
5454

5555
/// the '.pack' or '.idx' file to explode into loose objects
5656
#[argh(positional)]
57-
pub path: PathBuf,
57+
pub pack_path: PathBuf,
58+
59+
/// the path into which all objects should be written. Commonly '.git/objects'
60+
#[argh(positional)]
61+
pub object_path: Option<PathBuf>,
5862
}
5963

6064
/// Verify a pack
@@ -131,14 +135,16 @@ pub fn main() -> Result<()> {
131135
let thread_limit = cli.threads;
132136
match cli.subcommand {
133137
SubCommands::PackExplode(PackExplode {
134-
path,
138+
pack_path,
139+
object_path,
135140
verbose,
136141
check,
137142
delete_pack,
138143
}) => {
139144
let (_handle, progress) = prepare(verbose, "pack-explode");
140145
core::pack::explode::pack_or_pack_index(
141-
path,
146+
pack_path,
147+
object_path,
142148
check.unwrap_or(core::pack::explode::SafetyCheck::All),
143149
progress,
144150
delete_pack,

src/plumbing/pretty.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ mod options {
5959

6060
/// The '.pack' or '.idx' file to explode into loose objects
6161
#[structopt(parse(from_os_str))]
62-
path: PathBuf,
62+
pack_path: PathBuf,
63+
64+
/// The path into which all objects should be written. Commonly '.git/objects'
65+
#[structopt(parse(from_os_str))]
66+
object_path: Option<PathBuf>,
6367
},
6468
/// Verify the integrity of a pack or index file
6569
#[structopt(setting = AppSettings::ColoredHelp)]
@@ -221,13 +225,16 @@ pub fn main() -> Result<()> {
221225
progress,
222226
progress_keep_open,
223227
delete_pack,
224-
path,
228+
pack_path,
229+
object_path,
225230
} => prepare_and_run(
226231
"pack-explode",
227232
verbose,
228233
progress,
229234
progress_keep_open,
230-
move |progress, _out, _err| core::pack::explode::pack_or_pack_index(path, check, progress, delete_pack),
235+
move |progress, _out, _err| {
236+
core::pack::explode::pack_or_pack_index(pack_path, object_path, check, progress, delete_pack)
237+
},
231238
),
232239
Subcommands::PackVerify {
233240
path,

0 commit comments

Comments
 (0)