Skip to content

Commit

Permalink
Detect and report failure to start the diff-highlight process
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas committed Nov 26, 2016
1 parent 63b5582 commit e63ebc9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
9 changes: 8 additions & 1 deletion NEWS.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release notes
=============

master
------

Bug fixes:

- Add workaround for detecting failure to start the diff-highlight process.

tig-2.2.1
---------
Expand All @@ -25,7 +32,7 @@ Improvements:
- Bind 'Ctrl-D' and 'Ctrl-U' to half-page movements by default.
- manual: Mention how to change default Up/Down behavior in diff view.
Bug fixes
Bug fixes:
- Reorganize checking of libraries for termcap functions.
- Fix `:goto <id>` error message.
Expand Down
2 changes: 1 addition & 1 deletion include/tig/diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void diff_common_select(struct view *view, struct line *line, const char *change
void diff_save_line(struct view *view, struct diff_state *state, enum open_flags flags);
void diff_restore_line(struct view *view, struct diff_state *state);
enum status_code diff_init_highlight(struct view *view, struct diff_state *state);
void diff_done_highlight(struct diff_state *state);
bool diff_done_highlight(struct diff_state *state);

unsigned int diff_get_lineno(struct view *view, struct line *line);
const char *diff_get_pathname(struct view *view, struct line *line);
Expand Down
15 changes: 9 additions & 6 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ diff_init_highlight(struct view *view, struct diff_state *state)
return SUCCESS;
}

void
bool
diff_done_highlight(struct diff_state *state)
{
if (state->highlight) {
io_kill(&state->view_io);
io_done(&state->view_io);
}
if (!state->highlight)
return true;
io_kill(&state->view_io);
return io_done(&state->view_io);
}

struct diff_stat_context {
Expand Down Expand Up @@ -424,7 +424,10 @@ diff_read(struct view *view, struct buffer *buf, bool force_stop)
return diff_read_describe(view, buf, state);

if (!buf) {
diff_done_highlight(state);
if (!diff_done_highlight(state)) {
report("Failed run the diff-highlight program: %s", opt_diff_highlight);
return false;
}

/* Fall back to retry if no diff will be shown. */
if (view->lines == 0 && opt_file_args) {
Expand Down
8 changes: 4 additions & 4 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ io_done(struct io *io)
io_init(io);

while (pid > 0) {
int status;
int status = 0;
pid_t waiting = waitpid(pid, &status, 0);

if (waiting < 0) {
Expand All @@ -189,9 +189,7 @@ io_done(struct io *io)
return false;
}

if (WEXITSTATUS(status)) {
io->status = WEXITSTATUS(status);
}
io->status = WIFEXITED(status) ? WEXITSTATUS(status) : 0;

return waiting == pid &&
!WIFSIGNALED(status) &&
Expand Down Expand Up @@ -327,6 +325,8 @@ io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], c
}

execvp(argv[0], (char *const*) argv);

close(STDOUT_FILENO);
exit(errno);
}

Expand Down
8 changes: 6 additions & 2 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,12 @@ stage_read(struct view *view, struct buffer *buf, bool force_stop)
if (stage_line_type == LINE_STAT_UNTRACKED)
return pager_common_read(view, buf ? buf->data : NULL, LINE_DEFAULT, NULL);

if (!buf)
diff_done_highlight(&state->diff);
if (!buf) {
if (!diff_done_highlight(&state->diff)) {
report("Failed run the diff-highlight program: %s", opt_diff_highlight);
return true;
}
}

if (!buf && !view->lines && view->parent) {
maximize_view(view->parent, true);
Expand Down
38 changes: 37 additions & 1 deletion test/diff/diff-highlight-test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
. libgit.sh

file bin/diff-highlight <<EOF
sed 's/Add type parameter for js.Dynamic/Changed by diff-highlight/'
#!/bin/sh
exec sed 's/Add type parameter for js.Dynamic/Changed by diff-highlight/'
EOF

chmod +x bin/diff-highlight
Expand All @@ -20,6 +21,9 @@ steps '
:set diff-highlight = cat
:save-display diff-custom.screen
:set diff-highlight = program-that-does-not-exist
:save-display diff-failure.screen
'

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
Expand Down Expand Up @@ -89,3 +93,35 @@ index 65f914a..3aa4320 100644
[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff - line 1 of 24 100%
EOF

assert_equals 'diff-failure.screen' <<EOF
[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff 0%
EOF

0 comments on commit e63ebc9

Please sign in to comment.