=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- src/usr.bin/tmux/cmd.c 2009/10/26 21:42:04 1.27 +++ src/usr.bin/tmux/cmd.c 2009/11/02 16:24:29 1.28 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.27 2009/10/26 21:42:04 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.28 2009/11/02 16:24:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -488,19 +488,25 @@ *ambiguous = 0; /* - * Look for matches. Session names must be unique so an exact match - * can't be ambigious and can just be returned. + * Look for matches. First look for exact matches - session names must + * be unique so an exact match can't be ambigious and can just be + * returned. */ - sfound = NULL; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { if ((s = ARRAY_ITEM(&sessions, i)) == NULL) continue; - - /* Check for an exact match and return it if found. */ if (strcmp(name, s->name) == 0) return (s); - - /* Then check for pattern matches. */ + } + + /* + * Otherwise look for partial matches, returning early if it is found to + * be ambiguous. + */ + sfound = NULL; + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if ((s = ARRAY_ITEM(&sessions, i)) == NULL) + continue; if (strncmp(name, s->name, strlen(name)) == 0 || fnmatch(name, s->name, 0) == 0) { if (sfound != NULL) { @@ -510,7 +516,6 @@ sfound = s; } } - return (sfound); }