Skip to content

Commit

Permalink
Fix editing when stdin is redirected
Browse files Browse the repository at this point in the history
Closes #1330
  • Loading branch information
koutcher committed Apr 26, 2024
1 parent 663a69b commit b795fc3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bug fixes:
markers (regression in 2.5.9). (#1326)
- Fix keybinding with +[cmd] not triggering view refreshing. (#1324)
- Fix reopening the blame view from the main view.
- Fix editing when stdin is redirected. (#1330)

tig-2.5.9
---------
Expand Down
2 changes: 1 addition & 1 deletion include/tig/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool io_done(struct io *io);
bool io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], const char *argv[], int custom);
bool io_run(struct io *io, enum io_type type, const char *dir, char * const env[], const char *argv[]);
bool io_run_bg(const char **argv, const char *dir);
bool io_run_fg(const char **argv, const char *dir);
bool io_run_fg(const char **argv, const char *dir, int fd);
bool io_run_append(const char **argv, int fd);
bool io_eof(struct io *io);
int io_error(struct io *io);
Expand Down
2 changes: 1 addition & 1 deletion src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf
refresh();
endwin(); /* restore original tty modes */
tcsetattr(opt_tty.fd, TCSAFLUSH, opt_tty.attr);
ok = io_run_fg(argv, dir);
ok = io_run_fg(argv, dir, opt_tty.fd);
if (confirm || !ok) {
if (!ok && *notice)
fprintf(stderr, "%s", notice);
Expand Down
11 changes: 8 additions & 3 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ open_trace(int devnull, const char *argv[])
bool
io_trace(const char *fmt, ...)
{
static FILE *trace_out; /* Intensionally leaked. */
static FILE *trace_out; /* Intentionally leaked. */
va_list args;
int retval;

Expand Down Expand Up @@ -418,6 +418,11 @@ io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], c
close(pipefds[0]);
if (pipefds[1] != -1)
close(pipefds[1]);
} else {
if (custom != -1) {
dup2(custom, STDIN_FILENO);
close(custom);
}
}

if (dir && *dir && chdir(dir) == -1)
Expand Down Expand Up @@ -463,9 +468,9 @@ io_run_bg(const char **argv, const char *dir)
}

bool
io_run_fg(const char **argv, const char *dir)
io_run_fg(const char **argv, const char *dir, int fd)
{
return io_complete(IO_FG, argv, dir, -1);
return io_complete(IO_FG, argv, dir, fd);
}

bool
Expand Down
4 changes: 2 additions & 2 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,13 @@ status_revert(struct status *status, enum line_type type, bool has_none)
reset_argv[4] = NULL;
}

if (!io_run_fg(reset_argv, repo.exec_dir))
if (!io_run_fg(reset_argv, repo.exec_dir, -1))
return false;
if (status->old.mode == 0 && status->new.mode == 0)
return true;
}

return io_run_fg(checkout_argv, repo.exec_dir);
return io_run_fg(checkout_argv, repo.exec_dir, -1);
}

return false;
Expand Down

0 comments on commit b795fc3

Please sign in to comment.