From bcfa241b278eedd5a5fcba7054f4ff07b7adc534 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 16 Aug 2017 13:36:24 -0400 Subject: [PATCH] POC refresh display on filesystem change via entr --- src/display.c | 17 +++++++++++++++++ src/tig.c | 19 +++++++++++++++++++ test/main/filter-args-test | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/display.c b/src/display.c index 7179895e3..95aad05b6 100644 --- a/src/display.c +++ b/src/display.c @@ -701,6 +701,8 @@ get_input(int prompt_position, struct key *key) { struct view *view; int i, key_value, cursor_y, cursor_x; + static time_t last_winch = 0; + int winch_refresh_throttle = 1; if (prompt_position > 0) input_mode = true; @@ -766,6 +768,21 @@ get_input(int prompt_position, struct key *key) } else if (key_value == KEY_RESIZE) { int height, width; + bool refs_refreshed = false; + time_t now = time(NULL); + + if ((now - last_winch) >= winch_refresh_throttle) { + foreach_displayed_view (view, i) { + if (view_can_refresh(view)) { + if (!refs_refreshed) { + load_refs(true); + refs_refreshed = true; + } + refresh_view(view); + } + } + } + last_winch = now; getmaxyx(stdscr, height, width); diff --git a/src/tig.c b/src/tig.c index 4ae62e207..fcaf5e9f7 100644 --- a/src/tig.c +++ b/src/tig.c @@ -714,6 +714,14 @@ die_if_failed(enum status_code code, const char *msg) die("%s: %s", msg, get_status_message(code)); } +void +hangup_children(void) +{ + if (signal(SIGHUP, SIG_IGN) == SIG_ERR) + return; + killpg(getpid(), SIGHUP); +} + int main(int argc, const char *argv[]) { @@ -722,6 +730,8 @@ main(int argc, const char *argv[]) enum request request = parse_options(argc, argv, pager_mode); struct view *view; + atexit(hangup_children); + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) die("Failed to setup signal handler"); @@ -768,6 +778,15 @@ main(int argc, const char *argv[]) run_prompt_command(NULL, script_command); } + if (repo.git_dir[0]) { + const char *watcher_argv[] = { "sh", "-c", NULL, NULL }; + char cmd[SIZEOF_STR] = ""; + int restart_interval = 30; /* better would be 300 */ + string_format(cmd, "(export TIG_PID=\"%d\"; export ENTR_RESTART_SEC=\"%d\"; test \"$TIG_PID\" -gt 0 || exit; which entr || exit; sleep 1; while true; do git ls-files \"$(git rev-parse --show-toplevel)\" | entr -d kill -WINCH \"$TIG_PID\" & export ENTR_PID=\"$!\"; (sleep \"$ENTR_RESTART_SEC\" && kill -INT \"$ENTR_PID\") & export RESTARTER_PID=\"$!\"; wait \"$ENTR_PID\"; kill -WINCH \"$TIG_PID\"; kill -HUP \"$RESTARTER_PID\"; sleep 1; kill -0 \"$TIG_PID\" || break; done) &", getpid(), restart_interval); + watcher_argv[2] = cmd; + io_run_bg(watcher_argv, repo.cdup); + } + while (view_driver(display[current_view], request)) { view = display[current_view]; request = read_key_combo(view->keymap); diff --git a/test/main/filter-args-test b/test/main/filter-args-test index 784b754ad..f2031167c 100755 --- a/test/main/filter-args-test +++ b/test/main/filter-args-test @@ -27,7 +27,7 @@ steps ' test_tig --exclude=refs/remotes/origin/* --exclude=refs/heads/master --all -- common tracer -grep 'git rev-parse' < "$TIG_TRACE" > rev-parse.trace +grep 'git rev-parse' < "$TIG_TRACE" | grep -v 'TIG_PID' > rev-parse.trace grep 'git log' < "$TIG_TRACE" > log.trace assert_equals 'rev-parse.trace' <