Skip to content

Commit d2a3886

Browse files
committed
refactor: remove import-compressed feature
With bzip2-rs replacing the bzip2 crate, all of the dependencies for dealing with compressed import files are pure-rust. This obviates the main reason for guarding this capability with a feature (i.e. to avoid dynamic link dependencies).
1 parent a6bd194 commit d2a3886

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ name = "stg"
2121
anyhow = "1.0"
2222
anstyle = { version = "1.0", features = ["std"] }
2323
bstr = { version = "1.0", default-features = false, features = ["std"] }
24+
bzip2-rs = "0.1"
2425
clap = { version = "~4.2", default-features = false, features = [
2526
"color",
2627
"help",
@@ -32,26 +33,24 @@ clap = { version = "~4.2", default-features = false, features = [
3233
] }
3334
ctrlc = "3.2"
3435
encoding_rs = "0.8"
36+
flate2 = "1"
3537
gix = { version = "0.44", default-features = false, features = [] }
3638
indexmap = "1.9"
3739
is-terminal = "0.4"
3840
nom = { version = "7", default_features = false, features = [ "std" ] }
3941
serde = { version = "1.0", features = ["derive"] }
4042
serde_json = "1.0"
4143
strsim = "0.10"
44+
tar = "0.4"
4245
tempfile = "3"
4346
termcolor = "1.1"
4447
thiserror = "~1.0"
4548
time = { version = "0.3.21", default-features = false, features = ["local-offset", "formatting", "macros", "parsing"] }
4649

47-
bzip2-rs = { version = "0.1", optional = true }
4850
curl = { version = "0.4", optional = true }
49-
flate2 = { version = "1", optional = true }
50-
tar = { version = "0.4", optional = true }
5151

5252
[features]
53-
default = ["import-compressed", "import-url"]
54-
import-compressed = ["dep:bzip2-rs", "dep:flate2", "dep:tar"]
53+
default = ["import-url"]
5554
import-url = ["dep:curl"]
5655

5756
[profile.for-pkg]

src/cmd/import.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ fn import_url(stack: Stack, matches: &clap::ArgMatches) -> Result<()> {
312312
}
313313
}
314314

315-
#[cfg(feature = "import-compressed")]
316315
fn import_tgz_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Path) -> Result<()> {
317316
let source_file = std::fs::File::open(source_path)?;
318317
let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(source_file));
@@ -322,7 +321,6 @@ fn import_tgz_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Pat
322321
return import_series(stack, matches, Some(series_path.as_path()));
323322
}
324323

325-
#[cfg(feature = "import-compressed")]
326324
fn import_tbz2_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Path) -> Result<()> {
327325
let source_file = std::fs::File::open(source_path)?;
328326
let mut archive = tar::Archive::new(bzip2_rs::DecoderReader::new(source_file));
@@ -332,7 +330,6 @@ fn import_tbz2_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Pa
332330
return import_series(stack, matches, Some(series_path.as_path()));
333331
}
334332

335-
#[cfg(feature = "import-compressed")]
336333
fn import_tar_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Path) -> Result<()> {
337334
let source_file = std::fs::File::open(source_path)?;
338335
let mut archive = tar::Archive::new(source_file);
@@ -342,27 +339,6 @@ fn import_tar_series(stack: Stack, matches: &clap::ArgMatches, source_path: &Pat
342339
return import_series(stack, matches, Some(series_path.as_path()));
343340
}
344341

345-
#[cfg(not(feature = "import-compressed"))]
346-
fn import_tgz_series(_: Stack, _: &clap::ArgMatches, _: &Path) -> Result<()> {
347-
Err(anyhow!(
348-
"StGit not built with support for compressed series"
349-
))
350-
}
351-
352-
#[cfg(not(feature = "import-compressed"))]
353-
fn import_tbz2_series(_: Stack, _: &clap::ArgMatches, _: &Path) -> Result<()> {
354-
Err(anyhow!(
355-
"StGit not built with support for compressed series"
356-
))
357-
}
358-
359-
#[cfg(not(feature = "import-compressed"))]
360-
fn import_tar_series(_: Stack, _: &clap::ArgMatches, _: &Path) -> Result<()> {
361-
Err(anyhow!(
362-
"StGit not built with support for compressed series"
363-
))
364-
}
365-
366342
fn import_series(
367343
stack: Stack,
368344
matches: &clap::ArgMatches,
@@ -433,7 +409,6 @@ fn import_series(
433409
Ok(())
434410
}
435411

436-
#[cfg(feature = "import-compressed")]
437412
fn find_series_path(base: &Path) -> Result<PathBuf> {
438413
for entry in base.read_dir()? {
439414
let entry = entry?;
@@ -479,32 +454,16 @@ fn import_mail(stack: Stack, matches: &clap::ArgMatches, source_path: Option<&Pa
479454
Ok(())
480455
}
481456

482-
#[cfg(feature = "import-compressed")]
483457
fn read_gz(source_file: std::fs::File, content: &mut Vec<u8>) -> Result<()> {
484458
flate2::read::GzDecoder::new(source_file).read_to_end(content)?;
485459
Ok(())
486460
}
487461

488-
#[cfg(not(feature = "import-compressed"))]
489-
fn read_gz(_source_file: std::fs::File, _content: &mut Vec<u8>) -> Result<()> {
490-
Err(anyhow!(
491-
"StGit not built with support for compressed patches"
492-
))
493-
}
494-
495-
#[cfg(feature = "import-compressed")]
496462
fn read_bz2(source_file: std::fs::File, content: &mut Vec<u8>) -> Result<()> {
497463
bzip2_rs::DecoderReader::new(source_file).read_to_end(content)?;
498464
Ok(())
499465
}
500466

501-
#[cfg(not(feature = "import-compressed"))]
502-
fn read_bz2(_source_file: std::fs::File, _content: &mut Vec<u8>) -> Result<()> {
503-
Err(anyhow!(
504-
"StGit not built with support for compressed patches"
505-
))
506-
}
507-
508467
fn import_file<'repo>(
509468
stack: Stack<'repo>,
510469
matches: &clap::ArgMatches,

0 commit comments

Comments
 (0)