The branch, hooks has been updated
       via  47c174816efe404595fa05267ead6a8852468620 (commit)
      from  019529294f41bbccdbb895869cb7aa2dd7468bed (commit)

- Log -----------------------------------------------------------------
commit 47c174816efe404595fa05267ead6a8852468620
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    attach-session: cmdq->state fixes
    
    * Use cmdq->state for client 'c';
    * Use cloop for looping over clients array;
    * Reduce cflag check duplication to a single instance.
---
 cmd-attach-session.c |   79 ++++++++++++++++++-------------------------------
 1 files changed, 29 insertions(+), 50 deletions(-)

diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 3364509..c0dd9e3 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -36,7 +36,8 @@ const struct cmd_entry cmd_attach_session_entry = {
        "attach-session", "attach",
        "c:drt:", 0, 0,
        "[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
-       CMD_CANTNEST|CMD_STARTSERVER|CMD_PREP_SESSION_T|CMD_PREP_PANE_T,
+       CMD_CANTNEST|CMD_STARTSERVER|CMD_PREP_SESSION_T|CMD_PREP_PANE_T|
+           CMD_PREP_PREFERUNATTACHED,
        cmd_attach_session_exec
 };
 
@@ -44,7 +45,7 @@ enum cmd_retval
 cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag)
 {
        struct session          *s = cmdq->state.tflag.s;
-       struct client           *c = cmdq->state.c;
+       struct client           *cloop, *c = cmdq->state.c;
        struct winlink          *wl = cmdq->state.tflag.wl;
        struct window_pane      *wp = cmdq->state.tflag.wp;
        const char              *update;
@@ -68,6 +69,26 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, 
const char *cflag)
                session_set_current(s, wl);
        }
 
+       if (cflag != NULL) {
+               ft = format_create();
+               format_client(ft, c);
+               format_session(ft, s);
+               format_winlink(ft, s, s->curw);
+               format_window_pane(ft, s->curw->window->active);
+               cp = format_expand(ft, cflag);
+               format_free(ft);
+
+               fd = open(cp, O_RDONLY|O_DIRECTORY);
+               free(cp);
+               if (fd == -1) {
+                       cmdq_error(cmdq, "bad working directory: %s",
+                           strerror(errno));
+                       return (CMD_RETURN_ERROR);
+               }
+               close(s->cwd);
+               s->cwd = fd;
+       }
+
        if (cmdq->client->session != NULL) {
                if (dflag) {
                        /*
@@ -75,37 +96,16 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int 
rflag, const char *cflag)
                         * the same session as currently attached to.
                         */
                        for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
-                               c = ARRAY_ITEM(&clients, i);
-                               if (c == NULL || c->session != s)
+                               cloop = ARRAY_ITEM(&clients, i);
+                               if (cloop == NULL || cloop->session != s)
                                        continue;
-                               if (c == cmdq->client)
+                               if (cloop == cmdq->client)
                                        continue;
-                               server_write_client(c, MSG_DETACH,
-                                   c->session->name,
-                                   strlen(c->session->name) + 1);
+                               server_write_client(cloop, MSG_DETACH,
+                                   cloop->session->name,
+                                   strlen(cloop->session->name) + 1);
                        }
                }
-
-               if (cflag != NULL) {
-                       ft = format_create();
-                       format_client(ft, c);
-                       format_session(ft, s);
-                       format_winlink(ft, s, s->curw);
-                       format_window_pane(ft, s->curw->window->active);
-                       cp = format_expand(ft, cflag);
-                       format_free(ft);
-
-                       fd = open(cp, O_RDONLY|O_DIRECTORY);
-                       free(cp);
-                       if (fd == -1) {
-                               cmdq_error(cmdq, "bad working directory: %s",
-                                   strerror(errno));
-                               return (CMD_RETURN_ERROR);
-                       }
-                       close(s->cwd);
-                       s->cwd = fd;
-               }
-
                cmdq->client->session = s;
                notify_attached_session_changed(cmdq->client);
                session_update_activity(s);
@@ -118,27 +118,6 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int 
rflag, const char *cflag)
                        return (CMD_RETURN_ERROR);
                }
 
-               if (cflag != NULL) {
-                       ft = format_create();
-                       if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
-                               format_client(ft, c);
-                       format_session(ft, s);
-                       format_winlink(ft, s, s->curw);
-                       format_window_pane(ft, s->curw->window->active);
-                       cp = format_expand(ft, cflag);
-                       format_free(ft);
-
-                       fd = open(cp, O_RDONLY|O_DIRECTORY);
-                       free(cp);
-                       if (fd == -1) {
-                               cmdq_error(cmdq, "bad working directory: %s",
-                                   strerror(errno));
-                               return (CMD_RETURN_ERROR);
-                       }
-                       close(s->cwd);
-                       s->cwd = fd;
-               }
-
                if (rflag)
                        cmdq->client->flags |= CLIENT_READONLY;
 


-----------------------------------------------------------------------

Summary of changes:
 cmd-attach-session.c |   79 ++++++++++++++++++-------------------------------
 1 files changed, 29 insertions(+), 50 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

Reply via email to