The branch, hooks has been updated via bf3104efe6bcee2cda26f3efcc7c39e6b51773f5 (commit) via 34f574b7b780c3ab43d94d59747d24a5bfe87146 (commit) from 0ef7ad4d824b1dd039ac10a2513deda7d9356c85 (commit)
- Log ----------------------------------------------------------------- commit bf3104efe6bcee2cda26f3efcc7c39e6b51773f5 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Store hooks in the cmd_q instead of a flag. --- cmd-queue.c | 73 ++++++++++++++++++++++++---------------------------------- tmux.h | 5 ++- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/cmd-queue.c b/cmd-queue.c index 5a11722..057e399 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -165,17 +165,15 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix, struct cmd_q *cmdq) hook = hooks_find(hooks, s); free(s); - if (hook == NULL) { - cmdq->hooks_ran = 0; + if (hook == NULL) return (0); - } hooks_cmdq = cmdq_new(cmdq->client); hooks_cmdq->emptyfn = cmdq_hooks_emptyfn; hooks_cmdq->data = cmdq; - hooks_cmdq->hooks_ran = 1; + hooks_cmdq->for_hooks = 1; cmdq->references++; cmdq_run(hooks_cmdq, hook->cmdlist); @@ -185,19 +183,17 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix, struct cmd_q *cmdq) /* Callback when hooks cmdq is empty. */ void -cmdq_hooks_emptyfn(struct cmd_q *cmdq1) +cmdq_hooks_emptyfn(struct cmd_q *hooks_cmdq) { - struct cmd_q *cmdq = cmdq1->data; + struct cmd_q *cmdq = hooks_cmdq->data; - if (cmdq1->client_exit >= 0) - cmdq->client_exit = cmdq1->client_exit; + if (hooks_cmdq->client_exit >= 0) + cmdq->client_exit = hooks_cmdq->client_exit; - if (!cmdq_free(cmdq)) { - cmdq->hooks_ran = 1; + if (!cmdq_free(cmdq)) cmdq_continue(cmdq); - } - cmdq_free(cmdq1); + cmdq_free(hooks_cmdq); } /* Add command list to queue. */ @@ -218,9 +214,8 @@ cmdq_continue(struct cmd_q *cmdq) { struct cmd_q_item *next; struct cmd *cmd; - struct hooks *hooks; enum cmd_retval retval; - int empty, guard, flags; + int empty, flags; char s[1024]; notify_disable(); @@ -232,9 +227,9 @@ cmdq_continue(struct cmd_q *cmdq) /* * If the command isn't in the middle of running hooks (due to * CMD_RETURN_WAIT), move onto the next command; otherwise, leave the - * state of the queue as is; we're already in the correct place. + * state of the queue as it is. */ - if (!cmdq->during) { + if (cmdq->hooks == NULL) { if (cmdq->item == NULL) { cmdq->item = TAILQ_FIRST(&cmdq->queue); cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list); @@ -256,54 +251,46 @@ cmdq_continue(struct cmd_q *cmdq) flags = !!(cmd->flags & CMD_CONTROL); /* - * If we've come here because of running hooks, just - * run the command. + * If we've come back here after running hooks, skip + * the before hooks. */ - if (cmdq->during) + if (cmdq->hooks != NULL) goto skip; - guard = cmdq_guard(cmdq, "begin", flags); + cmdq_guard(cmdq, "begin", flags); if (cmd_prepare_state(cmd, cmdq) != 0) { - if (guard) - cmdq_guard(cmdq, "error", flags); + cmdq_guard(cmdq, "error", flags); break; } - + // XXX hooks changed/session destroyed? if (cmdq->state.tflag.s != NULL) - hooks = &cmdq->state.tflag.s->hooks; + cmdq->hooks = &cmdq->state.tflag.s->hooks; else if (cmdq->state.sflag.s != NULL) - hooks = &cmdq->state.sflag.s->hooks; + cmdq->hooks = &cmdq->state.sflag.s->hooks; else - hooks = &global_hooks; + cmdq->hooks = &global_hooks; - if (!cmdq->hooks_ran) { - if (cmdq_hooks_run(hooks, "before", cmdq)) { - cmdq->during = 1; - goto out; - } - } + if (!cmdq->for_hooks && cmdq_hooks_run(cmdq->hooks, + "before", cmdq)) + goto out; skip: - /* - * Runnning the hooks will change the state before each - * hook, so it needs to be restored afterwards. XXX not - * very obvious how this works from here... - */ if (cmd_prepare_state(cmd, cmdq) != 0) retval = CMD_RETURN_ERROR; else retval = cmd->entry->exec(cmd, cmdq); if (retval == CMD_RETURN_ERROR) { - if (guard) - cmdq_guard(cmdq, "error", flags); + cmdq_guard(cmdq, "error", flags); + cmdq->hooks = NULL; break; } - if (cmdq_hooks_run(hooks, "after", cmdq)) - goto out; + if (!cmdq->for_hooks && cmdq_hooks_run(cmdq->hooks, + "after", cmdq)) + retval = CMD_RETURN_WAIT; + cmdq->hooks = NULL; - if (guard) - cmdq_guard(cmdq, "end", flags); + cmdq_guard(cmdq, "end", flags); if (retval == CMD_RETURN_WAIT) goto out; diff --git a/tmux.h b/tmux.h index 63a9552..de594c2 100644 --- a/tmux.h +++ b/tmux.h @@ -1434,8 +1434,9 @@ struct cmd_q { void *data; TAILQ_ENTRY(cmd_q) waitentry; - int hooks_ran; - int during; + + int for_hooks; + struct hooks *hooks; }; /* Command definition. */ commit 34f574b7b780c3ab43d94d59747d24a5bfe87146 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Move emptyfn into cmd-queue.c, use data rather than adding a new orig_cmdq member, and some other changes. --- cmd-queue.c | 77 ++++++++++++++++++++++++++++++++++++---------------------- hooks.c | 16 ------------ tmux.h | 3 +- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/cmd-queue.c b/cmd-queue.c index 8d4f50f..5a11722 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -25,10 +25,8 @@ #include "tmux.h" -int cmdq_run_hook(struct hooks *, const char *, struct cmd *, - struct cmd_q *); - -int running_hooks = 0; +int cmdq_hooks_run(struct hooks *, const char *, struct cmd_q *); +void cmdq_hooks_emptyfn(struct cmd_q *); /* Create new command queue. */ struct cmd_q * @@ -151,34 +149,55 @@ cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist) } } -/* Run hooks based on the hooks prefix (before/after). */ +/* + * Run hooks based on the hooks prefix (before/after). Returns 1 if hooks are + * running. + */ int -cmdq_run_hook(struct hooks *hooks, const char *prefix, struct cmd *cmd, - struct cmd_q *cmdq) +cmdq_hooks_run(struct hooks *hooks, const char *prefix, struct cmd_q *cmdq) { + struct cmd *cmd = cmdq->cmd; struct hook *hook; struct cmd_q *hooks_cmdq; char *s; - int retval; xasprintf(&s, "%s-%s", prefix, cmd->entry->name); - if ((hook = hooks_find(hooks, s)) == NULL) { + hook = hooks_find(hooks, s); + free(s); + + if (hook == NULL) { cmdq->hooks_ran = 0; - retval = 0; - goto done; + return (0); } hooks_cmdq = cmdq_new(cmdq->client); - hooks_cmdq->orig_cmdq = cmdq; - hooks_cmdq->emptyfn = hooks_emptyfn; + + hooks_cmdq->emptyfn = cmdq_hooks_emptyfn; + hooks_cmdq->data = cmdq; + hooks_cmdq->hooks_ran = 1; + cmdq->references++; cmdq_run(hooks_cmdq, hook->cmdlist); - retval = 1; -done: - free(s); - return (retval); + return (1); +} + +/* Callback when hooks cmdq is empty. */ +void +cmdq_hooks_emptyfn(struct cmd_q *cmdq1) +{ + struct cmd_q *cmdq = cmdq1->data; + + if (cmdq1->client_exit >= 0) + cmdq->client_exit = cmdq1->client_exit; + + if (!cmdq_free(cmdq)) { + cmdq->hooks_ran = 1; + cmdq_continue(cmdq); + } + + cmdq_free(cmdq1); } /* Add command list to queue. */ @@ -210,11 +229,12 @@ cmdq_continue(struct cmd_q *cmdq) if (empty) goto empty; - /* If the command isn't in the middle of running hooks (due to + /* + * If the command isn't in the middle of running hooks (due to * CMD_RETURN_WAIT), move onto the next command; otherwise, leave the * state of the queue as is; we're already in the correct place. */ - if (cmdq->during == 0) { + if (!cmdq->during) { if (cmdq->item == NULL) { cmdq->item = TAILQ_FIRST(&cmdq->queue); cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list); @@ -239,8 +259,8 @@ cmdq_continue(struct cmd_q *cmdq) * If we've come here because of running hooks, just * run the command. */ - if (cmdq->during == 1) - goto runme; + if (cmdq->during) + goto skip; guard = cmdq_guard(cmdq, "begin", flags); @@ -257,20 +277,19 @@ cmdq_continue(struct cmd_q *cmdq) else hooks = &global_hooks; - if (cmdq->hooks_ran == 0) { - if (cmdq_run_hook(hooks, "before", cmd, - cmdq) == 1) { + if (!cmdq->hooks_ran) { + if (cmdq_hooks_run(hooks, "before", cmdq)) { cmdq->during = 1; goto out; } } + skip: /* - * hooks_run will change the state before each hook, so - * it needs to be restored afterwards. XXX not very - * obvious how this works from here... + * Runnning the hooks will change the state before each + * hook, so it needs to be restored afterwards. XXX not + * very obvious how this works from here... */ -runme: if (cmd_prepare_state(cmd, cmdq) != 0) retval = CMD_RETURN_ERROR; else @@ -280,7 +299,7 @@ runme: cmdq_guard(cmdq, "error", flags); break; } - if (cmdq_run_hook(hooks, "after", cmd, cmdq) == 1) + if (cmdq_hooks_run(hooks, "after", cmdq)) goto out; if (guard) diff --git a/hooks.c b/hooks.c index 80e1c89..58f9e8c 100644 --- a/hooks.c +++ b/hooks.c @@ -97,19 +97,3 @@ hooks_find(struct hooks *hooks, const char *name) } return (hook); } - -void -hooks_emptyfn(struct cmd_q *cmdq1) -{ - struct cmd_q *cmdq = cmdq1->orig_cmdq; - - if (cmdq1->client_exit >= 0) - cmdq->client_exit = cmdq1->client_exit; - - if (!cmdq_free(cmdq)) { - cmdq->hooks_ran = 1; - cmdq_continue(cmdq); - } - - cmdq_free(cmdq1); -} diff --git a/tmux.h b/tmux.h index 387fe3f..63a9552 100644 --- a/tmux.h +++ b/tmux.h @@ -1434,7 +1434,6 @@ struct cmd_q { void *data; TAILQ_ENTRY(cmd_q) waitentry; - struct cmd_q *orig_cmdq; int hooks_ran; int during; }; @@ -1585,7 +1584,7 @@ void hooks_add(struct hooks *, const char *, struct cmd_list *); void hooks_copy(struct hooks *, struct hooks *); void hooks_remove(struct hooks *, struct hook *); struct hook *hooks_find(struct hooks *, const char *); -void hooks_emptyfn(struct cmd_q *cmdq); + /* mode-key.c */ extern const struct mode_key_table mode_key_tables[]; extern struct mode_key_tree mode_key_tree_vi_edit; ----------------------------------------------------------------------- Summary of changes: cmd-queue.c | 118 +++++++++++++++++++++++++++++++---------------------------- hooks.c | 16 -------- tmux.h | 8 ++-- 3 files changed, 66 insertions(+), 76 deletions(-) hooks/post-receive -- tmux ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ tmux-cvs mailing list tmux-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-cvs