Skip to content

Commit bcfa241

Browse files
committed
POC refresh display on filesystem change via entr
1 parent aa4b1ac commit bcfa241

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/display.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ get_input(int prompt_position, struct key *key)
701701
{
702702
struct view *view;
703703
int i, key_value, cursor_y, cursor_x;
704+
static time_t last_winch = 0;
705+
int winch_refresh_throttle = 1;
704706

705707
if (prompt_position > 0)
706708
input_mode = true;
@@ -766,6 +768,21 @@ get_input(int prompt_position, struct key *key)
766768

767769
} else if (key_value == KEY_RESIZE) {
768770
int height, width;
771+
bool refs_refreshed = false;
772+
time_t now = time(NULL);
773+
774+
if ((now - last_winch) >= winch_refresh_throttle) {
775+
foreach_displayed_view (view, i) {
776+
if (view_can_refresh(view)) {
777+
if (!refs_refreshed) {
778+
load_refs(true);
779+
refs_refreshed = true;
780+
}
781+
refresh_view(view);
782+
}
783+
}
784+
}
785+
last_winch = now;
769786

770787
getmaxyx(stdscr, height, width);
771788

src/tig.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ die_if_failed(enum status_code code, const char *msg)
714714
die("%s: %s", msg, get_status_message(code));
715715
}
716716

717+
void
718+
hangup_children(void)
719+
{
720+
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
721+
return;
722+
killpg(getpid(), SIGHUP);
723+
}
724+
717725
int
718726
main(int argc, const char *argv[])
719727
{
@@ -722,6 +730,8 @@ main(int argc, const char *argv[])
722730
enum request request = parse_options(argc, argv, pager_mode);
723731
struct view *view;
724732

733+
atexit(hangup_children);
734+
725735
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
726736
die("Failed to setup signal handler");
727737

@@ -768,6 +778,15 @@ main(int argc, const char *argv[])
768778
run_prompt_command(NULL, script_command);
769779
}
770780

781+
if (repo.git_dir[0]) {
782+
const char *watcher_argv[] = { "sh", "-c", NULL, NULL };
783+
char cmd[SIZEOF_STR] = "";
784+
int restart_interval = 30; /* better would be 300 */
785+
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);
786+
watcher_argv[2] = cmd;
787+
io_run_bg(watcher_argv, repo.cdup);
788+
}
789+
771790
while (view_driver(display[current_view], request)) {
772791
view = display[current_view];
773792
request = read_key_combo(view->keymap);

test/main/filter-args-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ steps '
2727

2828
test_tig --exclude=refs/remotes/origin/* --exclude=refs/heads/master --all -- common tracer
2929

30-
grep 'git rev-parse' < "$TIG_TRACE" > rev-parse.trace
30+
grep 'git rev-parse' < "$TIG_TRACE" | grep -v 'TIG_PID' > rev-parse.trace
3131
grep 'git log' < "$TIG_TRACE" > log.trace
3232

3333
assert_equals 'rev-parse.trace' <<EOF

0 commit comments

Comments
 (0)