Fossil SCM

Improvements to the whatis() SQL function.

drh 2026-05-26 18:49 UTC pinned-forum-posts
Commit 5b31bb7fce15b1b75660ee4e7d43b85167eca6ff68935d66254ff9dbc019ce5e
1 file changed +8 -4
+8 -4
--- src/name.c
+++ src/name.c
@@ -1197,11 +1197,11 @@
11971197
*/
11981198
void whatis_rid(int rid, int flags, sqlite3_str *pOut){
11991199
Stmt q;
12001200
int cnt;
12011201
1202
- if( pOut ) sqlite3_str_append(pOut, "{", 1);
1202
+ if( pOut ) sqlite3_str_appendf(pOut, "{\"rid\":%d", rid);
12031203
12041204
/* Basic information about the object. */
12051205
db_prepare(&q,
12061206
"SELECT uuid, size, datetime(mtime,toLocal()), ipaddr"
12071207
" FROM blob, rcvfrom"
@@ -1219,10 +1219,12 @@
12191219
db_column_text(&q, 3));
12201220
}else{
12211221
whatis_line(pOut, "artifact","%s", db_column_text(&q,0));
12221222
whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1));
12231223
}
1224
+ }else if( pOut ){
1225
+ sqlite3_str_appendf(pOut, ",\"artifact\":null");
12241226
}
12251227
db_finalize(&q);
12261228
if( flags & WHATIS_HASHONLY ) return;
12271229
12281230
/* Report any symbolic tags on this artifact */
@@ -1240,11 +1242,11 @@
12401242
const char *zTag = (const char*)db_column_text(&q,0);
12411243
if( pOut ){
12421244
const char *zSep = cnt==0 ? ",tags:[" : ",";
12431245
sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
12441246
}else{
1245
- const char *zPrefix = cnt++ ? ", " : "tags: ";
1247
+ const char *zPrefix = cnt ? ", " : "tags: ";
12461248
fossil_print("%s%s", zPrefix, db_column_text(&q,0));
12471249
}
12481250
cnt++;
12491251
}
12501252
if( cnt ){
@@ -1270,11 +1272,11 @@
12701272
const char *zTag = (const char*)db_column_text(&q,0);
12711273
if( pOut ){
12721274
const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ",";
12731275
sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
12741276
}else{
1275
- const char *zPrefix = cnt++ ? ", " : "raw-tags: ";
1277
+ const char *zPrefix = cnt ? ", " : "raw-tags: ";
12761278
fossil_print("%s%s", zPrefix, db_column_text(&q,0));
12771279
}
12781280
cnt++;
12791281
}
12801282
if( cnt ){
@@ -1411,10 +1413,12 @@
14111413
"SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))"
14121414
" FROM description WHERE rid=%d", rid);
14131415
fossil_print("%s\n", zDesc);
14141416
fossil_free(zDesc);
14151417
}
1418
+
1419
+ if( pOut ) sqlite3_str_append(pOut, "}", 1);
14161420
}
14171421
14181422
/*
14191423
** Generate a description of artifact from it symbolic name.
14201424
*/
@@ -1499,11 +1503,11 @@
14991503
}
15001504
whatis_rid(db_column_int(&q, 0), mFlags, pOut);
15011505
}
15021506
db_finalize(&q);
15031507
}
1504
- if( pOut ) sqlite3_str_append(pOut, "]", 1);
1508
+ if( pOut ) sqlite3_str_append(pOut, "]}", 2);
15051509
}else if( rid==0 ){
15061510
if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
15071511
/* 0123456789 12 */
15081512
if( zFileName ){
15091513
fossil_print("%-12s%s\n", "name:", zFileName);
15101514
--- src/name.c
+++ src/name.c
@@ -1197,11 +1197,11 @@
1197 */
1198 void whatis_rid(int rid, int flags, sqlite3_str *pOut){
1199 Stmt q;
1200 int cnt;
1201
1202 if( pOut ) sqlite3_str_append(pOut, "{", 1);
1203
1204 /* Basic information about the object. */
1205 db_prepare(&q,
1206 "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr"
1207 " FROM blob, rcvfrom"
@@ -1219,10 +1219,12 @@
1219 db_column_text(&q, 3));
1220 }else{
1221 whatis_line(pOut, "artifact","%s", db_column_text(&q,0));
1222 whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1));
1223 }
 
 
1224 }
1225 db_finalize(&q);
1226 if( flags & WHATIS_HASHONLY ) return;
1227
1228 /* Report any symbolic tags on this artifact */
@@ -1240,11 +1242,11 @@
1240 const char *zTag = (const char*)db_column_text(&q,0);
1241 if( pOut ){
1242 const char *zSep = cnt==0 ? ",tags:[" : ",";
1243 sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
1244 }else{
1245 const char *zPrefix = cnt++ ? ", " : "tags: ";
1246 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
1247 }
1248 cnt++;
1249 }
1250 if( cnt ){
@@ -1270,11 +1272,11 @@
1270 const char *zTag = (const char*)db_column_text(&q,0);
1271 if( pOut ){
1272 const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ",";
1273 sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
1274 }else{
1275 const char *zPrefix = cnt++ ? ", " : "raw-tags: ";
1276 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
1277 }
1278 cnt++;
1279 }
1280 if( cnt ){
@@ -1411,10 +1413,12 @@
1411 "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))"
1412 " FROM description WHERE rid=%d", rid);
1413 fossil_print("%s\n", zDesc);
1414 fossil_free(zDesc);
1415 }
 
 
1416 }
1417
1418 /*
1419 ** Generate a description of artifact from it symbolic name.
1420 */
@@ -1499,11 +1503,11 @@
1499 }
1500 whatis_rid(db_column_int(&q, 0), mFlags, pOut);
1501 }
1502 db_finalize(&q);
1503 }
1504 if( pOut ) sqlite3_str_append(pOut, "]", 1);
1505 }else if( rid==0 ){
1506 if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
1507 /* 0123456789 12 */
1508 if( zFileName ){
1509 fossil_print("%-12s%s\n", "name:", zFileName);
1510
--- src/name.c
+++ src/name.c
@@ -1197,11 +1197,11 @@
1197 */
1198 void whatis_rid(int rid, int flags, sqlite3_str *pOut){
1199 Stmt q;
1200 int cnt;
1201
1202 if( pOut ) sqlite3_str_appendf(pOut, "{\"rid\":%d", rid);
1203
1204 /* Basic information about the object. */
1205 db_prepare(&q,
1206 "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr"
1207 " FROM blob, rcvfrom"
@@ -1219,10 +1219,12 @@
1219 db_column_text(&q, 3));
1220 }else{
1221 whatis_line(pOut, "artifact","%s", db_column_text(&q,0));
1222 whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1));
1223 }
1224 }else if( pOut ){
1225 sqlite3_str_appendf(pOut, ",\"artifact\":null");
1226 }
1227 db_finalize(&q);
1228 if( flags & WHATIS_HASHONLY ) return;
1229
1230 /* Report any symbolic tags on this artifact */
@@ -1240,11 +1242,11 @@
1242 const char *zTag = (const char*)db_column_text(&q,0);
1243 if( pOut ){
1244 const char *zSep = cnt==0 ? ",tags:[" : ",";
1245 sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
1246 }else{
1247 const char *zPrefix = cnt ? ", " : "tags: ";
1248 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
1249 }
1250 cnt++;
1251 }
1252 if( cnt ){
@@ -1270,11 +1272,11 @@
1272 const char *zTag = (const char*)db_column_text(&q,0);
1273 if( pOut ){
1274 const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ",";
1275 sqlite3_str_appendf(pOut, "%s%J", zSep, zTag);
1276 }else{
1277 const char *zPrefix = cnt ? ", " : "raw-tags: ";
1278 fossil_print("%s%s", zPrefix, db_column_text(&q,0));
1279 }
1280 cnt++;
1281 }
1282 if( cnt ){
@@ -1411,10 +1413,12 @@
1413 "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))"
1414 " FROM description WHERE rid=%d", rid);
1415 fossil_print("%s\n", zDesc);
1416 fossil_free(zDesc);
1417 }
1418
1419 if( pOut ) sqlite3_str_append(pOut, "}", 1);
1420 }
1421
1422 /*
1423 ** Generate a description of artifact from it symbolic name.
1424 */
@@ -1499,11 +1503,11 @@
1503 }
1504 whatis_rid(db_column_int(&q, 0), mFlags, pOut);
1505 }
1506 db_finalize(&q);
1507 }
1508 if( pOut ) sqlite3_str_append(pOut, "]}", 2);
1509 }else if( rid==0 ){
1510 if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){
1511 /* 0123456789 12 */
1512 if( zFileName ){
1513 fossil_print("%-12s%s\n", "name:", zFileName);
1514

Keyboard Shortcuts

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