Skip to content

Commit 5ad6fee

Browse files
expose delta-create in gix cli
1 parent 7bf07c8 commit 5ad6fee

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ gitoxide-core-tools-archive = ["gitoxide-core/archive"]
138138
## A sub-command to clean the worktree from untracked and ignored files.
139139
gitoxide-core-tools-clean = ["gitoxide-core/clean"]
140140

141+
## A sub-command to create a pack with delta compression.
142+
## NOTE: This is an experimental feature and may change in the future.
143+
gitoxide-core-tools-delta-create = ["gitoxide-core/experimental-delta-create"]
144+
141145
#! ### Building Blocks for mutually exclusive networking
142146
#! Blocking and async features are mutually exclusive and cause a compile-time error. This also means that `cargo … --all-features` will fail.
143147
#! Within each section, features can be combined.

src/plumbing/main.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,36 @@ pub fn main() -> Result<()> {
925925
},
926926
)
927927
}
928+
#[cfg(feature = "gitoxide-core-tools-delta-create")]
929+
free::pack::Subcommands::DeltaCreate {
930+
repository,
931+
statistics,
932+
nondeterministic_count,
933+
pack_cache_size_mb,
934+
counting_threads,
935+
object_cache_size_mb,
936+
output_directory,
937+
} => prepare_and_run(
938+
"pack-create",
939+
trace,
940+
verbose,
941+
progress,
942+
progress_keep_open,
943+
core::pack::create::PROGRESS_RANGE,
944+
move |progress, out, _err| {
945+
let input = stdin_or_bail()?;
946+
let repository = repository.unwrap_or_else(|| PathBuf::from("."));
947+
let context = core::pack::delta_create::Context {
948+
thread_limit,
949+
nondeterministic_thread_count: nondeterministic_count.then_some(counting_threads),
950+
pack_cache_size_in_bytes: pack_cache_size_mb.unwrap_or(0) * 1_000_000,
951+
object_cache_size_in_bytes: object_cache_size_mb.unwrap_or(0) * 1_000_000,
952+
statistics: if statistics { Some(format) } else { None },
953+
out,
954+
};
955+
core::pack::delta_create::delta_create(repository, input, output_directory, progress, context)
956+
},
957+
),
928958
#[cfg(feature = "gitoxide-core-async-client")]
929959
free::pack::Subcommands::Receive {
930960
protocol,

src/plumbing/options/free.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,53 @@ pub mod pack {
184184
/// Otherwise the expansion mode is 'tree-traversal' by default.
185185
tips: Vec<OsString>,
186186
},
187+
#[cfg(feature = "gitoxide-core-tools-delta-create")]
188+
/// Create a new pack with customized delta topological relationships. NOTE: This is an experimental feature and may change in the future.
189+
DeltaCreate {
190+
#[clap(long, short = 'r')]
191+
/// the directory containing the '.git' repository from which objects should be read.
192+
repository: Option<PathBuf>,
193+
194+
#[clap(long, default_value_t = 3, requires = "nondeterministic_count")]
195+
/// The amount of threads to use when counting and the `--nondeterminisitc-count` flag is set, defaulting
196+
/// to the globally configured threads.
197+
///
198+
/// Use it to have different trade-offs between counting performance and cost in terms of CPU, as the scaling
199+
/// here is everything but linear. The effectiveness of each core seems to be no more than 30%.
200+
counting_threads: usize,
201+
202+
#[clap(long)]
203+
/// if set, the counting phase may be accelerated using multithreading.
204+
///
205+
/// On the flip side, however, one will loose deterministic counting results which affects the
206+
/// way the resulting pack is structured.
207+
nondeterministic_count: bool,
208+
209+
#[clap(long, short = 's')]
210+
/// If set statistical information will be presented to inform about pack creation details.
211+
/// It's a form of instrumentation for developers to help improve pack generation.
212+
statistics: bool,
213+
214+
#[clap(long)]
215+
/// The size in megabytes for a cache to speed up pack access for packs with long delta chains.
216+
/// It is shared among all threads, so 4 threads would use their own cache 1/4th of the size.
217+
///
218+
/// If unset, no cache will be used.
219+
pack_cache_size_mb: Option<usize>,
220+
221+
#[clap(long)]
222+
/// The size in megabytes for a cache to speed up accessing entire objects, bypassing object database access when hit.
223+
/// It is shared among all threads, so 4 threads would use their own cache 1/4th of the size.
224+
///
225+
/// This cache type is currently only effective when using the 'diff-tree' object expansion.
226+
///
227+
/// If unset, no cache will be used.
228+
object_cache_size_mb: Option<usize>,
229+
230+
/// The directory into which to write the pack file.
231+
#[clap(long, short = 'o')]
232+
output_directory: Option<PathBuf>,
233+
},
187234
/// Use the gix-protocol to receive a pack, emulating a clone.
188235
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
189236
Receive {

0 commit comments

Comments
 (0)