Add back the support for difftools

main
trivernis 8 months ago
parent c4d2d3c72b
commit 1493797ace
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

243
Cargo.lock generated

@ -39,15 +39,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anstream"
version = "0.6.7"
@ -111,17 +102,6 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -419,21 +399,6 @@ dependencies = [
"chksum-hash-sha2-512",
]
[[package]]
name = "clap"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"ansi_term",
"atty",
"bitflags 1.3.2",
"strsim 0.8.0",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap"
version = "4.4.17"
@ -453,7 +418,7 @@ dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim 0.10.0",
"strsim",
]
[[package]]
@ -462,7 +427,7 @@ version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck 0.4.1",
"heck",
"proc-macro2",
"quote",
"syn 2.0.48",
@ -492,7 +457,7 @@ version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
dependencies = [
"encode_unicode 0.3.6",
"encode_unicode",
"lazy_static",
"libc",
"unicode-width",
@ -543,27 +508,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "csv"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
dependencies = [
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
dependencies = [
"memchr",
]
[[package]]
name = "dashmap"
version = "5.5.3"
@ -618,16 +562,6 @@ dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
@ -640,23 +574,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dot-silo"
version = "0.4.1"
dependencies = [
"chksum",
"clap 4.4.17",
"clap",
"dialoguer",
"dirs",
"figment",
@ -668,7 +591,6 @@ dependencies = [
"log",
"miette",
"pretty_env_logger",
"prettydiff",
"serde",
"serde_json",
"sys-info",
@ -695,12 +617,6 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "encode_unicode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "encoding_rs"
version = "0.8.33"
@ -1707,30 +1623,12 @@ version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.3"
@ -1882,7 +1780,7 @@ version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
dependencies = [
"hermit-abi 0.3.3",
"hermit-abi",
"rustix",
"windows-sys 0.52.0",
]
@ -2005,7 +1903,7 @@ dependencies = [
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"textwrap 0.15.2",
"textwrap",
"thiserror",
"unicode-width",
]
@ -2062,7 +1960,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.3",
"hermit-abi",
"libc",
]
@ -2102,15 +2000,6 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "pad"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3"
dependencies = [
"unicode-width",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -2236,56 +2125,6 @@ dependencies = [
"log",
]
[[package]]
name = "prettydiff"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ff1fec61082821f8236cf6c0c14e8172b62ce8a72a0eedc30d3b247bb68dc11"
dependencies = [
"ansi_term",
"pad",
"prettytable-rs",
"structopt",
]
[[package]]
name = "prettytable-rs"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
dependencies = [
"csv",
"encode_unicode 1.0.0",
"is-terminal",
"lazy_static",
"term",
"unicode-width",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.76"
@ -2479,12 +2318,6 @@ dependencies = [
"untrusted",
]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "ryu"
version = "1.0.16"
@ -2634,42 +2467,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "structopt"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
"clap 2.34.0",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck 0.3.3",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "supports-color"
version = "2.1.0"
@ -2764,17 +2567,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "term"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
dependencies = [
"dirs-next",
"rustversion",
"winapi",
]
[[package]]
name = "termcolor"
version = "1.4.1"
@ -2794,15 +2586,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.15.2"
@ -3039,12 +2822,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-width"
version = "0.1.11"
@ -3074,12 +2851,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.4"

@ -24,7 +24,6 @@ lazy_static = "1.4.0"
log = "0.4.20"
miette = { version = "5.10.0", features = ["serde", "fancy"] }
pretty_env_logger = "0.5.0"
prettydiff = "0.6.4"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
sys-info = "0.9.1"

@ -6,6 +6,7 @@ use figment::{
};
use miette::{Context, IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use which::which;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SiloConfig {
@ -18,12 +19,21 @@ pub struct SiloConfig {
impl Default for SiloConfig {
fn default() -> Self {
Self {
diff_tool: String::from("diff"),
diff_tool: detect_difftool(),
template_context: HashMap::new(),
}
}
}
fn detect_difftool() -> String {
["difft", "delta", "diff"]
.into_iter()
.filter(|t| which(t).is_ok())
.map(String::from)
.next()
.unwrap_or_else(|| String::from("diff"))
}
/// Read the configuration file from the user config directory
/// with overrides from the `repo.toml` file
/// and the `repo.local.toml` config file

@ -3,13 +3,13 @@ use std::{
io::Write,
mem,
path::{Path, PathBuf},
process::Command,
};
use chksum::sha2_256::chksum;
use dialoguer::Confirm;
use miette::{Context, IntoDiagnostic, Result};
use prettydiff::diff_lines;
use tempfile::NamedTempFile;
@ -17,12 +17,14 @@ use super::FsAccess;
pub struct BufferedFsAccess {
mappings: Vec<(NamedTempFile, PathBuf)>,
diff_tool: String,
}
impl BufferedFsAccess {
pub fn new() -> Self {
pub fn with_difftool(diff_tool: String) -> Self {
Self {
mappings: Vec::new(),
diff_tool,
}
}
}
@ -57,7 +59,7 @@ impl FsAccess for BufferedFsAccess {
let mut drop_list = Vec::new();
for (tmp, dst) in mappings {
if confirm_write(tmp.path(), &dst)? {
if confirm_write(&self.diff_tool, tmp.path(), &dst)? {
ensure_parent(dst.parent().unwrap())?;
fs::copy(tmp.path(), &dst)
.into_diagnostic()
@ -80,7 +82,7 @@ fn tmpfile() -> Result<NamedTempFile> {
.context("failed to create tmp file")
}
fn confirm_write(new: &Path, old: &Path) -> Result<bool> {
fn confirm_write(diff_tool: &str, new: &Path, old: &Path) -> Result<bool> {
if !old.exists() {
return Ok(true);
}
@ -95,17 +97,17 @@ fn confirm_write(new: &Path, old: &Path) -> Result<bool> {
return Ok(true);
}
let cont_new = fs::read_to_string(new)
Command::new(diff_tool)
.arg(old)
.arg(new)
.spawn()
.into_diagnostic()
.context("reading a")?;
let cont_old = fs::read_to_string(old)
.context("spawn diff tool")?
.wait()
.into_diagnostic()
.context("reading b")?;
.context("wait for diff tool to exit")?;
println!();
println!(
"\n=== Changes to {old:?}\n{}\n=== End of Changes\n",
diff_lines(&cont_old, &cont_new)
);
Confirm::new()
.with_prompt("Do you want to apply these changes?")
.interact()

@ -34,7 +34,9 @@ impl SiloRepo {
pub fn apply(&self) -> Result<()> {
let cwd = dirs::home_dir().unwrap_or(env::current_dir().into_diagnostic()?);
let fs_access: Box<dyn FsAccess> = Box::new(BufferedFsAccess::new());
let fs_access: Box<dyn FsAccess> = Box::new(BufferedFsAccess::with_difftool(
self.config.diff_tool.to_owned(),
));
let mut ctx = ApplyContext {
config: self.config.clone(),
fs: fs_access,

Loading…
Cancel
Save