Fossil SCM

Minor consistency fix about ambiguous sub-command dispatch and error reporting, see related [forum:/forumpost/48d6de4f8e2afdde|forum post].

mgagnon 2022-04-06 16:42 trunk merge
Commit 512905efd351e3b60dcc572f1d241187ed87db601a4256dcb8313574937d9467
2 files changed +10 -3 +1 -1
+10 -3
--- src/dispatch.c
+++ src/dispatch.c
@@ -125,11 +125,13 @@
125125
&& strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){
126126
if( aCommand[lwr].eCmdFlags & eType ){
127127
if( mid<0 ){
128128
mid = lwr; /* Potential ambiguous prefix */
129129
}else{
130
- return 2; /* Confirmed ambiguous prefix */
130
+ if( aCommand[lwr].xFunc != aCommand[mid].xFunc ){
131
+ return 2; /* Confirmed ambiguous prefix */
132
+ }
131133
}
132134
}
133135
}
134136
if( mid>=0 ){
135137
*ppCmd = &aCommand[mid];
@@ -207,16 +209,21 @@
207209
return 0;
208210
}
209211
210212
/*
211213
** 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.
213215
*/
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
+){
215221
int i;
216222
int nPrefix = (int)strlen(zPrefix);
217223
for(i=FOSSIL_FIRST_CMD; i<MX_COMMAND; i++){
224
+ if( (aCommand[i].eCmdFlags & eType)==0 ) continue;
218225
if( strncmp(zPrefix, aCommand[i].zName, nPrefix)==0 ){
219226
blob_appendf(pList, " %s", aCommand[i].zName);
220227
}
221228
}
222229
}
223230
--- 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 @@
911911
fossil_exit(0);
912912
#endif
913913
}else if( rc==2 ){
914914
Blob couldbe;
915915
blob_init(&couldbe,0,0);
916
- dispatch_matching_names(zCmdName, &couldbe);
916
+ dispatch_matching_names(zCmdName, CMDFLAG_COMMAND, &couldbe);
917917
fossil_print("%s: ambiguous command prefix: %s\n"
918918
"%s: could be any of:%s\n"
919919
"%s: use \"help\" for more information\n",
920920
g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]);
921921
fossil_exit(1);
922922
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button