Skip to content

Commit c4c5678

Browse files
committed
'index' with its own sub-commands (#279)
Cleanup to prepare for multi-index
1 parent fb64af4 commit c4c5678

File tree

10 files changed

+145
-120
lines changed

10 files changed

+145
-120
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
3535
* [x] **create** - create a pack from given objects or tips of the commit graph.
3636
* [ ] **send** - create a pack and send it using the pack protocol to stdout, similar to 'git-upload-pack',
3737
for consumption by **pack-receive** or _git-receive-pack_
38-
* [x] [index from data](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
39-
* [ ] support for thin packs (as needed for fetch/pull)
38+
* **index**
39+
* [x] [create](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
40+
* [x] support for thin packs (as needed for fetch/pull)
4041
* **commitgraph**
4142
* [x] **verify** - assure that a commitgraph is consistent
4243
* **remote**

Diff for: src/plumbing/main.rs

+38-36
Original file line numberDiff line numberDiff line change
@@ -177,42 +177,6 @@ pub fn main() -> Result<()> {
177177
)
178178
},
179179
),
180-
pack::Subcommands::IndexFromData {
181-
iteration_mode,
182-
pack_path,
183-
directory,
184-
} => prepare_and_run(
185-
"pack-index-from-data",
186-
verbose,
187-
progress,
188-
progress_keep_open,
189-
core::pack::index::PROGRESS_RANGE,
190-
move |progress, out, _err| {
191-
use gitoxide_core::pack::index::PathOrRead;
192-
let input = if let Some(path) = pack_path {
193-
PathOrRead::Path(path)
194-
} else {
195-
if atty::is(atty::Stream::Stdin) {
196-
anyhow::bail!(
197-
"Refusing to read from standard input as no path is given, but it's a terminal."
198-
)
199-
}
200-
PathOrRead::Read(Box::new(std::io::stdin()))
201-
};
202-
core::pack::index::from_pack(
203-
input,
204-
directory,
205-
progress,
206-
core::pack::index::Context {
207-
thread_limit,
208-
iteration_mode,
209-
format,
210-
out,
211-
should_interrupt: &git_repository::interrupt::IS_INTERRUPTED,
212-
},
213-
)
214-
},
215-
),
216180
pack::Subcommands::Explode {
217181
check,
218182
sink_compress,
@@ -277,6 +241,44 @@ pub fn main() -> Result<()> {
277241
},
278242
)
279243
.map(|_| ()),
244+
pack::Subcommands::Index(subcommands) => match subcommands {
245+
pack::index::Subcommands::Create {
246+
iteration_mode,
247+
pack_path,
248+
directory,
249+
} => prepare_and_run(
250+
"pack-index-from-data",
251+
verbose,
252+
progress,
253+
progress_keep_open,
254+
core::pack::index::PROGRESS_RANGE,
255+
move |progress, out, _err| {
256+
use gitoxide_core::pack::index::PathOrRead;
257+
let input = if let Some(path) = pack_path {
258+
PathOrRead::Path(path)
259+
} else {
260+
if atty::is(atty::Stream::Stdin) {
261+
anyhow::bail!(
262+
"Refusing to read from standard input as no path is given, but it's a terminal."
263+
)
264+
}
265+
PathOrRead::Read(Box::new(std::io::stdin()))
266+
};
267+
core::pack::index::from_pack(
268+
input,
269+
directory,
270+
progress,
271+
core::pack::index::Context {
272+
thread_limit,
273+
iteration_mode,
274+
format,
275+
out,
276+
should_interrupt: &git_repository::interrupt::IS_INTERRUPTED,
277+
},
278+
)
279+
},
280+
),
281+
},
280282
},
281283
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
282284
Subcommands::Remote(subcommands) => match subcommands {

Diff for: src/plumbing/options.rs

+45-31
Original file line numberDiff line numberDiff line change
@@ -153,37 +153,9 @@ pub mod pack {
153153
/// If unset, they will be discarded.
154154
directory: Option<PathBuf>,
155155
},
156-
/// create a pack index from a pack data file.
157-
#[clap(setting = AppSettings::DisableVersionFlag)]
158-
IndexFromData {
159-
/// Specify how to iterate the pack, defaults to 'verify'
160-
///
161-
/// Valid values are
162-
///
163-
/// **as-is** do not do anything and expect the pack file to be valid as per the trailing hash,
164-
/// **verify** the input ourselves and validate that it matches with the hash provided in the pack,
165-
/// **restore** hash the input ourselves and ignore failing entries, instead finish the pack with the hash we computed
166-
/// to keep as many objects as possible.
167-
#[clap(
168-
long,
169-
short = 'i',
170-
default_value = "verify",
171-
possible_values(core::pack::index::IterationMode::variants())
172-
)]
173-
iteration_mode: core::pack::index::IterationMode,
174-
175-
/// Path to the pack file to read (with .pack extension).
176-
///
177-
/// If unset, the pack file is expected on stdin.
178-
#[clap(long, short = 'p')]
179-
pack_path: Option<PathBuf>,
180-
181-
/// The folder into which to place the pack and the generated index file
182-
///
183-
/// If unset, only informational output will be provided to standard output.
184-
#[clap(parse(from_os_str))]
185-
directory: Option<PathBuf>,
186-
},
156+
/// Subcommands for interacting with pack indices (.idx)
157+
#[clap(subcommand)]
158+
Index(index::Subcommands),
187159
/// Dissolve a pack into its loose objects.
188160
///
189161
/// Note that this effectively removes delta compression for an average compression of 2x, creating one file per object in the process.
@@ -261,6 +233,48 @@ pub mod pack {
261233
path: PathBuf,
262234
},
263235
}
236+
237+
///
238+
pub mod index {
239+
use clap::AppSettings;
240+
use gitoxide_core as core;
241+
use std::path::PathBuf;
242+
243+
#[derive(Debug, clap::Parser)]
244+
pub enum Subcommands {
245+
/// create a pack index from a pack data file.
246+
#[clap(setting = AppSettings::DisableVersionFlag)]
247+
Create {
248+
/// Specify how to iterate the pack, defaults to 'verify'
249+
///
250+
/// Valid values are
251+
///
252+
/// **as-is** do not do anything and expect the pack file to be valid as per the trailing hash,
253+
/// **verify** the input ourselves and validate that it matches with the hash provided in the pack,
254+
/// **restore** hash the input ourselves and ignore failing entries, instead finish the pack with the hash we computed
255+
/// to keep as many objects as possible.
256+
#[clap(
257+
long,
258+
short = 'i',
259+
default_value = "verify",
260+
possible_values(core::pack::index::IterationMode::variants())
261+
)]
262+
iteration_mode: core::pack::index::IterationMode,
263+
264+
/// Path to the pack file to read (with .pack extension).
265+
///
266+
/// If unset, the pack file is expected on stdin.
267+
#[clap(long, short = 'p')]
268+
pack_path: Option<PathBuf>,
269+
270+
/// The folder into which to place the pack and the generated index file
271+
///
272+
/// If unset, only informational output will be provided to standard output.
273+
#[clap(parse(from_os_str))]
274+
directory: Option<PathBuf>,
275+
},
276+
}
277+
}
264278
}
265279

266280
///

Diff for: tests/journey/gix.sh

+59-51
Original file line numberDiff line numberDiff line change
@@ -196,68 +196,76 @@ title "gix pack"
196196
fi
197197
)
198198
)
199-
title "gix pack index-from-data"
200-
(with "the 'index-from-data' sub-command"
201-
snapshot="$snapshot/index-from-data"
202-
PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
203-
(with "a valid and complete pack file"
204-
(with "NO output directory specified"
205-
(with "pack file passed as file"
206-
it "generates an index into a sink and outputs pack and index information" && {
207-
WITH_SNAPSHOT="$snapshot/no-output-dir-success" \
208-
expect_run $SUCCESSFULLY "$exe_plumbing" pack index-from-data -p "$PACK_FILE"
209-
}
199+
(with "the 'index' sub-command"
200+
snapshot="$snapshot/index"
201+
title "gix pack index create"
202+
(with "the 'create' sub-command"
203+
snapshot="$snapshot/create"
204+
PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
205+
(with "a valid and complete pack file"
206+
(with "NO output directory specified"
207+
(with "pack file passed as file"
208+
it "generates an index into a sink and outputs pack and index information" && {
209+
WITH_SNAPSHOT="$snapshot/no-output-dir-success" \
210+
expect_run $SUCCESSFULLY "$exe_plumbing" pack index create -p "$PACK_FILE"
211+
}
212+
)
213+
(with "pack file passed from stdin"
214+
it "generates an index into a sink and outputs pack and index information" && {
215+
WITH_SNAPSHOT="$snapshot/no-output-dir-success" \
216+
expect_run $SUCCESSFULLY "$exe_plumbing" pack index create < "$PACK_FILE"
217+
}
218+
if test "$kind" = "max"; then
219+
(with "--format json"
220+
it "generates the index into a sink and outputs information as JSON" && {
221+
WITH_SNAPSHOT="$snapshot/no-output-dir-as-json-success" \
222+
expect_run $SUCCESSFULLY "$exe_plumbing" --format json pack index create < "$PACK_FILE"
223+
}
224+
)
225+
fi
226+
)
210227
)
211-
(with "pack file passed from stdin"
212-
it "generates an index into a sink and outputs pack and index information" && {
213-
WITH_SNAPSHOT="$snapshot/no-output-dir-success" \
214-
expect_run $SUCCESSFULLY "$exe_plumbing" pack index-from-data < "$PACK_FILE"
215-
}
216-
if test "$kind" = "max"; then
217-
(with "--format json"
218-
it "generates the index into a sink and outputs information as JSON" && {
219-
WITH_SNAPSHOT="$snapshot/no-output-dir-as-json-success" \
220-
expect_run $SUCCESSFULLY "$exe_plumbing" --format json pack index-from-data < "$PACK_FILE"
228+
(sandbox
229+
(with "with an output directory specified"
230+
it "generates an index and outputs information" && {
231+
WITH_SNAPSHOT="$snapshot/output-dir-success" \
232+
expect_run $SUCCESSFULLY "$exe_plumbing" pack index create -p "$PACK_FILE" "$PWD"
233+
}
234+
it "writes the index and pack into the directory (they have the same names, different suffixes)" && {
235+
WITH_SNAPSHOT="$snapshot/output-dir-content" \
236+
expect_run $SUCCESSFULLY ls
221237
}
222238
)
223-
fi
224239
)
225240
)
226-
(sandbox
227-
(with "with an output directory specified"
228-
it "generates an index and outputs information" && {
229-
WITH_SNAPSHOT="$snapshot/output-dir-success" \
230-
expect_run $SUCCESSFULLY "$exe_plumbing" pack index-from-data -p "$PACK_FILE" "$PWD"
231-
}
232-
it "writes the index and pack into the directory (they have the same names, different suffixes)" && {
233-
WITH_SNAPSHOT="$snapshot/output-dir-content" \
234-
expect_run $SUCCESSFULLY ls
241+
(with "'restore' iteration mode"
242+
(sandbox
243+
cp "${PACK_FILE}" .
244+
PACK_FILE="${PACK_FILE##*/}"
245+
"$jtt" mess-in-the-middle "${PACK_FILE}"
246+
247+
it "generates an index and outputs information (instead of failing)" && {
248+
WITH_SNAPSHOT="$snapshot/output-dir-restore-success" \
249+
expect_run $SUCCESSFULLY "$exe_plumbing" pack index create -i restore -p "$PACK_FILE" "$PWD"
235250
}
251+
252+
if test "$kind" = "max"; then
253+
(with "--format json and the very same output directory"
254+
it "generates the index, overwriting existing files, and outputs information as JSON" && {
255+
WITH_SNAPSHOT="$snapshot/output-dir-restore-as-json-success" \
256+
SNAPSHOT_FILTER=remove-paths \
257+
expect_run $SUCCESSFULLY "$exe_plumbing" --format json pack index create -i restore $PWD < "$PACK_FILE"
258+
}
259+
)
260+
fi
236261
)
237262
)
238263
)
239-
(with "'restore' iteration mode"
240-
(sandbox
241-
cp "${PACK_FILE}" .
242-
PACK_FILE="${PACK_FILE##*/}"
243-
"$jtt" mess-in-the-middle "${PACK_FILE}"
264+
)
244265

245-
it "generates an index and outputs information (instead of failing)" && {
246-
WITH_SNAPSHOT="$snapshot/output-dir-restore-success" \
247-
expect_run $SUCCESSFULLY "$exe_plumbing" pack index-from-data -i restore -p "$PACK_FILE" "$PWD"
248-
}
266+
title "gix pack multi-index"
267+
(with "the 'multi-index' sub-command"
249268

250-
if test "$kind" = "max"; then
251-
(with "--format json and the very same output directory"
252-
it "generates the index, overwriting existing files, and outputs information as JSON" && {
253-
WITH_SNAPSHOT="$snapshot/output-dir-restore-as-json-success" \
254-
SNAPSHOT_FILTER=remove-paths \
255-
expect_run $SUCCESSFULLY "$exe_plumbing" --format json pack index-from-data -i restore $PWD < "$PACK_FILE"
256-
}
257-
)
258-
fi
259-
)
260-
)
261269
)
262270

263271
title "gix pack explode"

0 commit comments

Comments
 (0)