Skip to content

Commit 0a33b24

Browse files
committed
refactor
1 parent 29b9c23 commit 0a33b24

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

Diff for: git-odb/src/pack/data/decode.rs

+3
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ impl File {
360360

361361
let last_result_size = last_result_size.expect("at least one delta chain item");
362362
// uneven chains leave the target buffer after the source buffer
363+
// FIXME(Performance) If delta-chains are uneven, we know we will have to copy bytes over here
364+
// Instead we could use a different start buffer, to naturally end up with the result in the
365+
// right one.
363366
if chain.len() % 2 == 1 {
364367
// this seems inverted, but remember: we swapped the buffers on the last iteration
365368
target_buf[..last_result_size].copy_from_slice(&source_buf[..last_result_size]);

Diff for: git-odb/src/pack/index/traverse/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ impl Default for Algorithm {
138138

139139
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
140140
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
141-
pub struct Context {
141+
pub struct Options {
142142
pub algorithm: Algorithm,
143143
pub thread_limit: Option<usize>,
144144
pub check: SafetyCheck,
145145
}
146146

147-
impl Default for Context {
147+
impl Default for Options {
148148
fn default() -> Self {
149149
Self {
150150
algorithm: Algorithm::Lookup,
@@ -159,11 +159,11 @@ impl index::File {
159159
pub fn traverse<P, C, Processor>(
160160
&self,
161161
pack: &pack::data::File,
162-
Context {
162+
Options {
163163
algorithm,
164164
thread_limit,
165165
check,
166-
}: Context,
166+
}: Options,
167167
progress: Option<P>,
168168
new_processor: impl Fn() -> Processor + Send + Sync,
169169
make_cache: impl Fn() -> C + Send + Sync,

Diff for: git-odb/src/pack/index/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl index::File {
9292
Some((pack, mode, algorithm)) => self
9393
.traverse(
9494
pack,
95-
index::traverse::Context {
95+
index::traverse::Options {
9696
algorithm,
9797
thread_limit,
9898
check: index::traverse::SafetyCheck::All,

Diff for: gitoxide-core/src/pack/explode.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Context, Result};
1+
use anyhow::{anyhow, Result};
22
use git_features::progress::{self, Progress};
33
use git_object::{owned, HashKind};
44
use git_odb::{loose, pack, Write};
@@ -124,19 +124,29 @@ impl OutputWriter {
124124
}
125125
}
126126

127+
pub struct Context {
128+
pub thread_limit: Option<usize>,
129+
pub delete_pack: bool,
130+
pub sink_compress: bool,
131+
}
132+
127133
pub fn pack_or_pack_index<P>(
128134
pack_path: impl AsRef<Path>,
129135
object_path: Option<impl AsRef<Path>>,
130136
check: SafetyCheck,
131-
thread_limit: Option<usize>,
132137
progress: Option<P>,
133-
delete_pack: bool,
134-
sink_compress: bool,
138+
Context {
139+
thread_limit,
140+
delete_pack,
141+
sink_compress,
142+
}: Context,
135143
) -> Result<()>
136144
where
137145
P: Progress,
138146
<P as Progress>::SubProgress: Send,
139147
{
148+
use anyhow::Context;
149+
140150
let path = pack_path.as_ref();
141151
let bundle = pack::Bundle::at(path).with_context(|| {
142152
format!(
@@ -154,17 +164,17 @@ where
154164

155165
let algorithm = object_path
156166
.as_ref()
157-
.map(|_| {
167+
.map(|_| pack::index::traverse::Algorithm::Lookup)
168+
.unwrap_or_else(|| {
158169
if sink_compress {
159170
pack::index::traverse::Algorithm::Lookup
160171
} else {
161172
pack::index::traverse::Algorithm::DeltaTreeLookup
162173
}
163-
})
164-
.unwrap_or(pack::index::traverse::Algorithm::Lookup);
174+
});
165175
let mut progress = bundle.index.traverse(
166176
&bundle.pack,
167-
pack::index::traverse::Context {
177+
pack::index::traverse::Options {
168178
algorithm,
169179
thread_limit,
170180
check: check.into(),

Diff for: src/plumbing/lean.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ pub fn main() -> Result<()> {
155155
pack_path,
156156
object_path,
157157
check.unwrap_or(core::pack::explode::SafetyCheck::All),
158-
thread_limit,
159158
progress,
160-
delete_pack,
161-
sink_compress,
159+
core::pack::explode::Context {
160+
thread_limit,
161+
delete_pack,
162+
sink_compress,
163+
},
162164
)
163165
}
164166
SubCommands::PackVerify(PackVerify {

Diff for: src/plumbing/pretty.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ pub fn main() -> Result<()> {
246246
pack_path,
247247
object_path,
248248
check,
249-
thread_limit,
250249
progress,
251-
delete_pack,
252-
sink_compress,
250+
core::pack::explode::Context {
251+
thread_limit,
252+
delete_pack,
253+
sink_compress,
254+
},
253255
)
254256
},
255257
),

Diff for: tasks.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
* [x] to sink
4040
* [x] to disk
4141
* [x] progress
42-
* [ ] option to compress sink input too
42+
* [x] option to compress sink input too
43+
* [ ] unrelated: see if delta-decode buffer optimization can work easily
4344
* [ ] --verify
4445
* [ ] statistics
4546

0 commit comments

Comments
 (0)