Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dandavison/delta
Browse files Browse the repository at this point in the history
* 'master' of github.com:dandavison/delta:
  Terminate process gracefully on error in diff() (dandavison#685)
  Update Dockerfile
  Bump bitflags from 1.2.1 to 1.3.1 (dandavison#682)
  Bump syntect from 4.5.0 to 4.6.0 (dandavison#674)
  clippy
  Ignore clippy needless_borrow lint failures
  • Loading branch information
Kr1ss-XD committed Aug 12, 2021
2 parents 3255b67 + 35ba0dc commit 9baf7c8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
args: -- -D warnings --allow clippy::needless_borrow

coverage:
name: Code coverage
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/main.rs"
ansi_colours = "1.0.4"
ansi_term = "0.12.1"
atty = "0.2.14"
bitflags = "1.2.1"
bitflags = "1.3.1"
box_drawing = "0.1.2"
bytelines = "2.2.2"
console = "0.14.1"
Expand All @@ -41,7 +41,7 @@ default-features = false
features = []

[dependencies.syntect]
version = "4.5.0"
version = "4.6.0"
default-features = false
features = ["parsing", "assets", "yaml-load", "dump-load", "regex-onig"]

Expand Down
1 change: 1 addition & 0 deletions etc/docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.PHONY: delta-ubuntu
delta-ubuntu:
docker build -f ubuntu.Dockerfile -t delta-ubuntu .
1 change: 1 addition & 0 deletions etc/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The docker image built here is intended for investigating delta issues, for example when they are OS-dependent.
8 changes: 4 additions & 4 deletions etc/docker/ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ubuntu:20.04
FROM ubuntu:latest

RUN apt-get update && \
apt-get install -y curl git less

RUN curl -OL https://github.com/dandavison/delta/releases/download/0.4.5/delta-0.4.5-x86_64-unknown-linux-gnu.tar.gz && \
tar -xzvf delta-0.4.5-x86_64-unknown-linux-gnu.tar.gz
RUN curl -OL https://github.com/dandavison/delta/releases/download/0.8.3/delta-0.8.3-x86_64-unknown-linux-musl.tar.gz && \
tar -xzvf delta-0.8.3-x86_64-unknown-linux-musl.tar.gz

WORKDIR delta-0.4.5-x86_64-unknown-linux-gnu
WORKDIR delta-0.8.3-x86_64-unknown-linux-musl

ENV PATH="${PWD}:${PATH}"

Expand Down
41 changes: 25 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ pub mod errors {
}

#[cfg(not(tarpaulin_include))]
/// `Ok` of the `Result` contains with the exit code value
// An Ok result contains the desired process exit code. Note that 1 is used to
// report that two files differ when delta is called with two positional
// arguments and without standard input; 2 is used to report a real problem.
fn run_app() -> std::io::Result<i32> {
let assets = HighlightingAssets::new();
let opt = cli::Opt::from_args_and_git_config(&mut git_config::GitConfig::try_create(), assets);
Expand Down Expand Up @@ -120,31 +122,38 @@ fn diff(
writer: &mut dyn Write,
) -> i32 {
use std::io::BufReader;
let die = || {
if minus_file.is_none() || plus_file.is_none() {
eprintln!(
"\
The main way to use delta is to configure it as the pager for git: \
see https://github.com/dandavison/delta#configuration. \
You can also use delta to diff two files: `delta file_A file_B`."
);
process::exit(config.error_exit_code);
};
return config.error_exit_code;
}
let minus_file = minus_file.unwrap();
let plus_file = plus_file.unwrap();

let diff_command = "git";
let minus_file = minus_file.unwrap_or_else(die);
let plus_file = plus_file.unwrap_or_else(die);
let diff_command_path = match grep_cli::resolve_binary(PathBuf::from(diff_command)) {
Ok(path) => path,
Err(_) => return config.error_exit_code,
Err(err) => {
eprintln!("Failed to resolve command '{}': {}", diff_command, err);
return config.error_exit_code;
}
};
let mut diff_process = process::Command::new(diff_command_path)

let diff_process = process::Command::new(diff_command_path)
.args(&["diff", "--no-index"])
.args(&[minus_file, plus_file])
.stdout(process::Stdio::piped())
.spawn()
.unwrap_or_else(|err| {
eprintln!("Failed to execute the command '{}': {}", diff_command, err);
process::exit(config.error_exit_code);
});
.spawn();

if let Err(err) = diff_process {
eprintln!("Failed to execute the command '{}': {}", diff_command, err);
return config.error_exit_code;
}
let mut diff_process = diff_process.unwrap();

let exit_code = diff_process
.wait()
Expand All @@ -154,7 +163,7 @@ You can also use delta to diff two files: `delta file_A file_B`."
.code()
.unwrap_or_else(|| {
eprintln!("'{}' process terminated without exit status.", diff_command);
process::exit(config.error_exit_code);
config.error_exit_code
});

if let Err(error) = delta(
Expand All @@ -163,10 +172,10 @@ You can also use delta to diff two files: `delta file_A file_B`."
&config,
) {
match error.kind() {
ErrorKind::BrokenPipe => process::exit(0),
ErrorKind::BrokenPipe => return 0,
_ => {
eprintln!("{}", error);
process::exit(config.error_exit_code);
return config.error_exit_code;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn _parse_file_path(s: &str, git_diff_name: bool) -> String {
// index·d00491f..0cfbf08·100644␊
// ---·a/a·b├──┤␊
// +++·b/c·d├──┤␊
match s.strip_suffix("\t").unwrap_or(s) {
match s.strip_suffix('\t').unwrap_or(s) {
path if path == "/dev/null" => "/dev/null",
path if git_diff_name && DIFF_PREFIXES.iter().any(|s| path.starts_with(s)) => &path[2..],
path if git_diff_name => &path,
Expand Down

0 comments on commit 9baf7c8

Please sign in to comment.