Fossil SCM

Improve "whatis" output when in "filename" mode and parse supported whatis options when using "fossil all whatis".

mgagnon 2023-12-14 16:29 trunk
Commit e1e9da26f68fe963e203063852f8e19910d8ecf8ee4c6f8f1b030c830411aa5b
2 files changed +13 -9 +11 -7
+13 -9
--- src/allrepo.c
+++ src/allrepo.c
@@ -31,12 +31,14 @@
3131
const char *z = find_option(zArg, zShort, 0);
3232
if( z!=0 ){
3333
blob_appendf(pExtra, " %s", z);
3434
}
3535
}
36
-static void collect_argument_value(Blob *pExtra, const char *zArg){
37
- const char *zValue = find_option(zArg, 0, 1);
36
+static void collect_argument_value(
37
+ Blob *pExtra, const char *zArg, const char *zShort
38
+){
39
+ const char *zValue = find_option(zArg, zShort, 1);
3840
if( zValue ){
3941
if( zValue[0] ){
4042
blob_appendf(pExtra, " --%s %$", zArg, zValue);
4143
}else{
4244
blob_appendf(pExtra, " --%s \"\"", zArg);
@@ -210,19 +212,19 @@
210212
}
211213
blob_appendf(&extra, " %$", zDest);
212214
}else if( fossil_strcmp(zCmd, "clean")==0 ){
213215
zCmd = "clean --chdir";
214216
collect_argument(&extra, "allckouts",0);
215
- collect_argument_value(&extra, "case-sensitive");
216
- collect_argument_value(&extra, "clean");
217
+ collect_argument_value(&extra, "case-sensitive", 0);
218
+ collect_argument_value(&extra, "clean", 0);
217219
collect_argument(&extra, "dirsonly",0);
218220
collect_argument(&extra, "disable-undo",0);
219221
collect_argument(&extra, "dotfiles",0);
220222
collect_argument(&extra, "emptydirs",0);
221223
collect_argument(&extra, "force","f");
222
- collect_argument_value(&extra, "ignore");
223
- collect_argument_value(&extra, "keep");
224
+ collect_argument_value(&extra, "ignore", 0);
225
+ collect_argument_value(&extra, "keep", 0);
224226
collect_argument(&extra, "no-prompt",0);
225227
collect_argument(&extra, "temp",0);
226228
collect_argument(&extra, "verbose","v");
227229
collect_argument(&extra, "whatif",0);
228230
useCheckouts = 1;
@@ -247,13 +249,13 @@
247249
zCmd = "extras --chdir";
248250
}else{
249251
zCmd = "extras --header --chdir";
250252
}
251253
collect_argument(&extra, "abs-paths",0);
252
- collect_argument_value(&extra, "case-sensitive");
254
+ collect_argument_value(&extra, "case-sensitive", 0);
253255
collect_argument(&extra, "dotfiles",0);
254
- collect_argument_value(&extra, "ignore");
256
+ collect_argument_value(&extra, "ignore", 0);
255257
collect_argument(&extra, "rel-paths",0);
256258
useCheckouts = 1;
257259
stopOnError = 0;
258260
quiet = 1;
259261
}else if( fossil_strcmp(zCmd, "git")==0 ){
@@ -280,11 +282,11 @@
280282
zCmd = "rebuild";
281283
collect_argument(&extra, "cluster",0);
282284
collect_argument(&extra, "compress",0);
283285
collect_argument(&extra, "compress-only",0);
284286
collect_argument(&extra, "noverify",0);
285
- collect_argument_value(&extra, "pagesize");
287
+ collect_argument_value(&extra, "pagesize", 0);
286288
collect_argument(&extra, "vacuum",0);
287289
collect_argument(&extra, "deanalyze",0);
288290
collect_argument(&extra, "analyze",0);
289291
collect_argument(&extra, "wal",0);
290292
collect_argument(&extra, "stats",0);
@@ -414,10 +416,12 @@
414416
showLabel = 1;
415417
collect_argv(&extra, 3);
416418
}else if( fossil_strcmp(zCmd, "whatis")==0 ){
417419
zCmd = "whatis -q -R";
418420
quiet = 1;
421
+ collect_argument(&extra, "file", "f");
422
+ collect_argument_value(&extra, "type", 0);
419423
collect_argv(&extra, 3);
420424
}else{
421425
fossil_fatal("\"all\" subcommand should be one of: "
422426
"add cache changes clean dbstat extras fts-config git ignore "
423427
"info list ls pull push rebuild remote "
424428
--- src/allrepo.c
+++ src/allrepo.c
@@ -31,12 +31,14 @@
31 const char *z = find_option(zArg, zShort, 0);
32 if( z!=0 ){
33 blob_appendf(pExtra, " %s", z);
34 }
35 }
36 static void collect_argument_value(Blob *pExtra, const char *zArg){
37 const char *zValue = find_option(zArg, 0, 1);
 
 
38 if( zValue ){
39 if( zValue[0] ){
40 blob_appendf(pExtra, " --%s %$", zArg, zValue);
41 }else{
42 blob_appendf(pExtra, " --%s \"\"", zArg);
@@ -210,19 +212,19 @@
210 }
211 blob_appendf(&extra, " %$", zDest);
212 }else if( fossil_strcmp(zCmd, "clean")==0 ){
213 zCmd = "clean --chdir";
214 collect_argument(&extra, "allckouts",0);
215 collect_argument_value(&extra, "case-sensitive");
216 collect_argument_value(&extra, "clean");
217 collect_argument(&extra, "dirsonly",0);
218 collect_argument(&extra, "disable-undo",0);
219 collect_argument(&extra, "dotfiles",0);
220 collect_argument(&extra, "emptydirs",0);
221 collect_argument(&extra, "force","f");
222 collect_argument_value(&extra, "ignore");
223 collect_argument_value(&extra, "keep");
224 collect_argument(&extra, "no-prompt",0);
225 collect_argument(&extra, "temp",0);
226 collect_argument(&extra, "verbose","v");
227 collect_argument(&extra, "whatif",0);
228 useCheckouts = 1;
@@ -247,13 +249,13 @@
247 zCmd = "extras --chdir";
248 }else{
249 zCmd = "extras --header --chdir";
250 }
251 collect_argument(&extra, "abs-paths",0);
252 collect_argument_value(&extra, "case-sensitive");
253 collect_argument(&extra, "dotfiles",0);
254 collect_argument_value(&extra, "ignore");
255 collect_argument(&extra, "rel-paths",0);
256 useCheckouts = 1;
257 stopOnError = 0;
258 quiet = 1;
259 }else if( fossil_strcmp(zCmd, "git")==0 ){
@@ -280,11 +282,11 @@
280 zCmd = "rebuild";
281 collect_argument(&extra, "cluster",0);
282 collect_argument(&extra, "compress",0);
283 collect_argument(&extra, "compress-only",0);
284 collect_argument(&extra, "noverify",0);
285 collect_argument_value(&extra, "pagesize");
286 collect_argument(&extra, "vacuum",0);
287 collect_argument(&extra, "deanalyze",0);
288 collect_argument(&extra, "analyze",0);
289 collect_argument(&extra, "wal",0);
290 collect_argument(&extra, "stats",0);
@@ -414,10 +416,12 @@
414 showLabel = 1;
415 collect_argv(&extra, 3);
416 }else if( fossil_strcmp(zCmd, "whatis")==0 ){
417 zCmd = "whatis -q -R";
418 quiet = 1;
 
 
419 collect_argv(&extra, 3);
420 }else{
421 fossil_fatal("\"all\" subcommand should be one of: "
422 "add cache changes clean dbstat extras fts-config git ignore "
423 "info list ls pull push rebuild remote "
424
--- src/allrepo.c
+++ src/allrepo.c
@@ -31,12 +31,14 @@
31 const char *z = find_option(zArg, zShort, 0);
32 if( z!=0 ){
33 blob_appendf(pExtra, " %s", z);
34 }
35 }
36 static void collect_argument_value(
37 Blob *pExtra, const char *zArg, const char *zShort
38 ){
39 const char *zValue = find_option(zArg, zShort, 1);
40 if( zValue ){
41 if( zValue[0] ){
42 blob_appendf(pExtra, " --%s %$", zArg, zValue);
43 }else{
44 blob_appendf(pExtra, " --%s \"\"", zArg);
@@ -210,19 +212,19 @@
212 }
213 blob_appendf(&extra, " %$", zDest);
214 }else if( fossil_strcmp(zCmd, "clean")==0 ){
215 zCmd = "clean --chdir";
216 collect_argument(&extra, "allckouts",0);
217 collect_argument_value(&extra, "case-sensitive", 0);
218 collect_argument_value(&extra, "clean", 0);
219 collect_argument(&extra, "dirsonly",0);
220 collect_argument(&extra, "disable-undo",0);
221 collect_argument(&extra, "dotfiles",0);
222 collect_argument(&extra, "emptydirs",0);
223 collect_argument(&extra, "force","f");
224 collect_argument_value(&extra, "ignore", 0);
225 collect_argument_value(&extra, "keep", 0);
226 collect_argument(&extra, "no-prompt",0);
227 collect_argument(&extra, "temp",0);
228 collect_argument(&extra, "verbose","v");
229 collect_argument(&extra, "whatif",0);
230 useCheckouts = 1;
@@ -247,13 +249,13 @@
249 zCmd = "extras --chdir";
250 }else{
251 zCmd = "extras --header --chdir";
252 }
253 collect_argument(&extra, "abs-paths",0);
254 collect_argument_value(&extra, "case-sensitive", 0);
255 collect_argument(&extra, "dotfiles",0);
256 collect_argument_value(&extra, "ignore", 0);
257 collect_argument(&extra, "rel-paths",0);
258 useCheckouts = 1;
259 stopOnError = 0;
260 quiet = 1;
261 }else if( fossil_strcmp(zCmd, "git")==0 ){
@@ -280,11 +282,11 @@
282 zCmd = "rebuild";
283 collect_argument(&extra, "cluster",0);
284 collect_argument(&extra, "compress",0);
285 collect_argument(&extra, "compress-only",0);
286 collect_argument(&extra, "noverify",0);
287 collect_argument_value(&extra, "pagesize", 0);
288 collect_argument(&extra, "vacuum",0);
289 collect_argument(&extra, "deanalyze",0);
290 collect_argument(&extra, "analyze",0);
291 collect_argument(&extra, "wal",0);
292 collect_argument(&extra, "stats",0);
@@ -414,10 +416,12 @@
416 showLabel = 1;
417 collect_argv(&extra, 3);
418 }else if( fossil_strcmp(zCmd, "whatis")==0 ){
419 zCmd = "whatis -q -R";
420 quiet = 1;
421 collect_argument(&extra, "file", "f");
422 collect_argument_value(&extra, "type", 0);
423 collect_argv(&extra, 3);
424 }else{
425 fossil_fatal("\"all\" subcommand should be one of: "
426 "add cache changes clean dbstat extras fts-config git ignore "
427 "info list ls pull push rebuild remote "
428
+11 -7
--- src/name.c
+++ src/name.c
@@ -1163,23 +1163,21 @@
11631163
const char *zName, /* Symbolic name or full hash */
11641164
const char *zFileName,/* Optional: original filename (in file mode) */
11651165
const char *zType, /* Artifact type filter */
11661166
int mFlags /* WHATIS_* flags */
11671167
){
1168
- const char* zNameTitle = "name:";
11691168
int rid = symbolic_name_to_rid(zName, zType);
1170
- if( zFileName ){
1171
- fossil_print("%-12s%s\n", zNameTitle, zFileName);
1172
- zNameTitle = "hash:";
1173
- }
11741169
if( rid<0 ){
11751170
Stmt q;
11761171
int cnt = 0;
11771172
if( mFlags & WHATIS_REPO ){
11781173
fossil_print("\nrepository: %s\n", g.zRepositoryName);
11791174
}
1180
- fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
1175
+ if( zFileName ){
1176
+ fossil_print("%-12s%s\n", "name:", zFileName);
1177
+ }
1178
+ fossil_print("%-12s%s (ambiguous)\n", "hash:", zName);
11811179
db_prepare(&q,
11821180
"SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
11831181
zName, zName
11841182
);
11851183
while( db_step(&q)==SQLITE_ROW ){
@@ -1188,17 +1186,23 @@
11881186
}
11891187
db_finalize(&q);
11901188
}else if( rid==0 ){
11911189
if( (mFlags & WHATIS_OMIT_UNK)==0 ){
11921190
/* 0123456789 12 */
1191
+ if( zFileName ){
1192
+ fossil_print("%-12s%s\n", "name:", zFileName);
1193
+ }
11931194
fossil_print("unknown: %s\n", zName);
11941195
}
11951196
}else{
11961197
if( mFlags & WHATIS_REPO ){
11971198
fossil_print("\nrepository: %s\n", g.zRepositoryName);
11981199
}
1199
- fossil_print("%-12s%s\n", zNameTitle, zName);
1200
+ if( zFileName ){
1201
+ zName = zFileName;
1202
+ }
1203
+ fossil_print("%-12s%s\n", "name:", zName);
12001204
whatis_rid(rid, mFlags);
12011205
}
12021206
}
12031207
12041208
/*
12051209
--- src/name.c
+++ src/name.c
@@ -1163,23 +1163,21 @@
1163 const char *zName, /* Symbolic name or full hash */
1164 const char *zFileName,/* Optional: original filename (in file mode) */
1165 const char *zType, /* Artifact type filter */
1166 int mFlags /* WHATIS_* flags */
1167 ){
1168 const char* zNameTitle = "name:";
1169 int rid = symbolic_name_to_rid(zName, zType);
1170 if( zFileName ){
1171 fossil_print("%-12s%s\n", zNameTitle, zFileName);
1172 zNameTitle = "hash:";
1173 }
1174 if( rid<0 ){
1175 Stmt q;
1176 int cnt = 0;
1177 if( mFlags & WHATIS_REPO ){
1178 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1179 }
1180 fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
 
 
 
1181 db_prepare(&q,
1182 "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
1183 zName, zName
1184 );
1185 while( db_step(&q)==SQLITE_ROW ){
@@ -1188,17 +1186,23 @@
1188 }
1189 db_finalize(&q);
1190 }else if( rid==0 ){
1191 if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1192 /* 0123456789 12 */
 
 
 
1193 fossil_print("unknown: %s\n", zName);
1194 }
1195 }else{
1196 if( mFlags & WHATIS_REPO ){
1197 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1198 }
1199 fossil_print("%-12s%s\n", zNameTitle, zName);
 
 
 
1200 whatis_rid(rid, mFlags);
1201 }
1202 }
1203
1204 /*
1205
--- src/name.c
+++ src/name.c
@@ -1163,23 +1163,21 @@
1163 const char *zName, /* Symbolic name or full hash */
1164 const char *zFileName,/* Optional: original filename (in file mode) */
1165 const char *zType, /* Artifact type filter */
1166 int mFlags /* WHATIS_* flags */
1167 ){
 
1168 int rid = symbolic_name_to_rid(zName, zType);
 
 
 
 
1169 if( rid<0 ){
1170 Stmt q;
1171 int cnt = 0;
1172 if( mFlags & WHATIS_REPO ){
1173 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1174 }
1175 if( zFileName ){
1176 fossil_print("%-12s%s\n", "name:", zFileName);
1177 }
1178 fossil_print("%-12s%s (ambiguous)\n", "hash:", zName);
1179 db_prepare(&q,
1180 "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
1181 zName, zName
1182 );
1183 while( db_step(&q)==SQLITE_ROW ){
@@ -1188,17 +1186,23 @@
1186 }
1187 db_finalize(&q);
1188 }else if( rid==0 ){
1189 if( (mFlags & WHATIS_OMIT_UNK)==0 ){
1190 /* 0123456789 12 */
1191 if( zFileName ){
1192 fossil_print("%-12s%s\n", "name:", zFileName);
1193 }
1194 fossil_print("unknown: %s\n", zName);
1195 }
1196 }else{
1197 if( mFlags & WHATIS_REPO ){
1198 fossil_print("\nrepository: %s\n", g.zRepositoryName);
1199 }
1200 if( zFileName ){
1201 zName = zFileName;
1202 }
1203 fossil_print("%-12s%s\n", "name:", zName);
1204 whatis_rid(rid, mFlags);
1205 }
1206 }
1207
1208 /*
1209

Keyboard Shortcuts

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