Fossil SCM
Minor consistency fix about ambiguous sub-command dispatch and error reporting, see related [forum:/forumpost/48d6de4f8e2afdde|forum post].
Commit
512905efd351e3b60dcc572f1d241187ed87db601a4256dcb8313574937d9467
Parent
959807e91502d64…
2 files changed
+10
-3
+1
-1
+10
-3
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -125,11 +125,13 @@ | ||
| 125 | 125 | && strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){ |
| 126 | 126 | if( aCommand[lwr].eCmdFlags & eType ){ |
| 127 | 127 | if( mid<0 ){ |
| 128 | 128 | mid = lwr; /* Potential ambiguous prefix */ |
| 129 | 129 | }else{ |
| 130 | - return 2; /* Confirmed ambiguous prefix */ | |
| 130 | + if( aCommand[lwr].xFunc != aCommand[mid].xFunc ){ | |
| 131 | + return 2; /* Confirmed ambiguous prefix */ | |
| 132 | + } | |
| 131 | 133 | } |
| 132 | 134 | } |
| 133 | 135 | } |
| 134 | 136 | if( mid>=0 ){ |
| 135 | 137 | *ppCmd = &aCommand[mid]; |
| @@ -207,16 +209,21 @@ | ||
| 207 | 209 | return 0; |
| 208 | 210 | } |
| 209 | 211 | |
| 210 | 212 | /* |
| 211 | 213 | ** Fill Blob with a space-separated list of all command names that |
| 212 | -** match the prefix zPrefix. | |
| 214 | +** match the prefix zPrefix and the eType CMDFLAGS_ bits. | |
| 213 | 215 | */ |
| 214 | -void dispatch_matching_names(const char *zPrefix, Blob *pList){ | |
| 216 | +void dispatch_matching_names( | |
| 217 | + const char *zPrefix, /* name prefix */ | |
| 218 | + unsigned eType, /* CMDFLAG_ bits */ | |
| 219 | + Blob *pList /* space-separated list of command names */ | |
| 220 | +){ | |
| 215 | 221 | int i; |
| 216 | 222 | int nPrefix = (int)strlen(zPrefix); |
| 217 | 223 | for(i=FOSSIL_FIRST_CMD; i<MX_COMMAND; i++){ |
| 224 | + if( (aCommand[i].eCmdFlags & eType)==0 ) continue; | |
| 218 | 225 | if( strncmp(zPrefix, aCommand[i].zName, nPrefix)==0 ){ |
| 219 | 226 | blob_appendf(pList, " %s", aCommand[i].zName); |
| 220 | 227 | } |
| 221 | 228 | } |
| 222 | 229 | } |
| 223 | 230 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -125,11 +125,13 @@ | |
| 125 | && strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){ |
| 126 | if( aCommand[lwr].eCmdFlags & eType ){ |
| 127 | if( mid<0 ){ |
| 128 | mid = lwr; /* Potential ambiguous prefix */ |
| 129 | }else{ |
| 130 | return 2; /* Confirmed ambiguous prefix */ |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | if( mid>=0 ){ |
| 135 | *ppCmd = &aCommand[mid]; |
| @@ -207,16 +209,21 @@ | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | ** Fill Blob with a space-separated list of all command names that |
| 212 | ** match the prefix zPrefix. |
| 213 | */ |
| 214 | void dispatch_matching_names(const char *zPrefix, Blob *pList){ |
| 215 | int i; |
| 216 | int nPrefix = (int)strlen(zPrefix); |
| 217 | for(i=FOSSIL_FIRST_CMD; i<MX_COMMAND; i++){ |
| 218 | if( strncmp(zPrefix, aCommand[i].zName, nPrefix)==0 ){ |
| 219 | blob_appendf(pList, " %s", aCommand[i].zName); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -125,11 +125,13 @@ | |
| 125 | && strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){ |
| 126 | if( aCommand[lwr].eCmdFlags & eType ){ |
| 127 | if( mid<0 ){ |
| 128 | mid = lwr; /* Potential ambiguous prefix */ |
| 129 | }else{ |
| 130 | if( aCommand[lwr].xFunc != aCommand[mid].xFunc ){ |
| 131 | return 2; /* Confirmed ambiguous prefix */ |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | if( mid>=0 ){ |
| 137 | *ppCmd = &aCommand[mid]; |
| @@ -207,16 +209,21 @@ | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | ** Fill Blob with a space-separated list of all command names that |
| 214 | ** match the prefix zPrefix and the eType CMDFLAGS_ bits. |
| 215 | */ |
| 216 | void dispatch_matching_names( |
| 217 | const char *zPrefix, /* name prefix */ |
| 218 | unsigned eType, /* CMDFLAG_ bits */ |
| 219 | Blob *pList /* space-separated list of command names */ |
| 220 | ){ |
| 221 | int i; |
| 222 | int nPrefix = (int)strlen(zPrefix); |
| 223 | for(i=FOSSIL_FIRST_CMD; i<MX_COMMAND; i++){ |
| 224 | if( (aCommand[i].eCmdFlags & eType)==0 ) continue; |
| 225 | if( strncmp(zPrefix, aCommand[i].zName, nPrefix)==0 ){ |
| 226 | blob_appendf(pList, " %s", aCommand[i].zName); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 |
+1
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -911,11 +911,11 @@ | ||
| 911 | 911 | fossil_exit(0); |
| 912 | 912 | #endif |
| 913 | 913 | }else if( rc==2 ){ |
| 914 | 914 | Blob couldbe; |
| 915 | 915 | blob_init(&couldbe,0,0); |
| 916 | - dispatch_matching_names(zCmdName, &couldbe); | |
| 916 | + dispatch_matching_names(zCmdName, CMDFLAG_COMMAND, &couldbe); | |
| 917 | 917 | fossil_print("%s: ambiguous command prefix: %s\n" |
| 918 | 918 | "%s: could be any of:%s\n" |
| 919 | 919 | "%s: use \"help\" for more information\n", |
| 920 | 920 | g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]); |
| 921 | 921 | fossil_exit(1); |
| 922 | 922 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -911,11 +911,11 @@ | |
| 911 | fossil_exit(0); |
| 912 | #endif |
| 913 | }else if( rc==2 ){ |
| 914 | Blob couldbe; |
| 915 | blob_init(&couldbe,0,0); |
| 916 | dispatch_matching_names(zCmdName, &couldbe); |
| 917 | fossil_print("%s: ambiguous command prefix: %s\n" |
| 918 | "%s: could be any of:%s\n" |
| 919 | "%s: use \"help\" for more information\n", |
| 920 | g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]); |
| 921 | fossil_exit(1); |
| 922 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -911,11 +911,11 @@ | |
| 911 | fossil_exit(0); |
| 912 | #endif |
| 913 | }else if( rc==2 ){ |
| 914 | Blob couldbe; |
| 915 | blob_init(&couldbe,0,0); |
| 916 | dispatch_matching_names(zCmdName, CMDFLAG_COMMAND, &couldbe); |
| 917 | fossil_print("%s: ambiguous command prefix: %s\n" |
| 918 | "%s: could be any of:%s\n" |
| 919 | "%s: use \"help\" for more information\n", |
| 920 | g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]); |
| 921 | fossil_exit(1); |
| 922 |