mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:44:18 +00:00 
			
		
		
		
	Hoist some common code out of both branches of an if/else.
This commit is contained in:
		@@ -93,6 +93,24 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
 | 
				
			|||||||
		session_set_current(s, wl);
 | 
							session_set_current(s, wl);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (cflag != NULL) {
 | 
				
			||||||
 | 
							ft = format_create();
 | 
				
			||||||
 | 
							format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
 | 
				
			||||||
 | 
							    NULL, NULL);
 | 
				
			||||||
 | 
							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 (c->session != NULL) {
 | 
						if (c->session != NULL) {
 | 
				
			||||||
		if (dflag) {
 | 
							if (dflag) {
 | 
				
			||||||
			/*
 | 
								/*
 | 
				
			||||||
@@ -108,24 +126,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (cflag != NULL) {
 | 
					 | 
				
			||||||
			ft = format_create();
 | 
					 | 
				
			||||||
			format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
 | 
					 | 
				
			||||||
			    NULL, NULL);
 | 
					 | 
				
			||||||
			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 (!Eflag) {
 | 
							if (!Eflag) {
 | 
				
			||||||
			update = options_get_string(&s->options,
 | 
								update = options_get_string(&s->options,
 | 
				
			||||||
			    "update-environment");
 | 
								    "update-environment");
 | 
				
			||||||
@@ -146,24 +146,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
 | 
				
			|||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (cflag != NULL) {
 | 
					 | 
				
			||||||
			ft = format_create();
 | 
					 | 
				
			||||||
			format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
 | 
					 | 
				
			||||||
			    NULL, NULL);
 | 
					 | 
				
			||||||
			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)
 | 
							if (rflag)
 | 
				
			||||||
			c->flags |= CLIENT_READONLY;
 | 
								c->flags |= CLIENT_READONLY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user