Fossil SCM
Improvements to the whatis() SQL function.
Commit
5b31bb7fce15b1b75660ee4e7d43b85167eca6ff68935d66254ff9dbc019ce5e
Parent
db8c6f909d43c5d…
1 file changed
+8
-4
+8
-4
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -1197,11 +1197,11 @@ | ||
| 1197 | 1197 | */ |
| 1198 | 1198 | void whatis_rid(int rid, int flags, sqlite3_str *pOut){ |
| 1199 | 1199 | Stmt q; |
| 1200 | 1200 | int cnt; |
| 1201 | 1201 | |
| 1202 | - if( pOut ) sqlite3_str_append(pOut, "{", 1); | |
| 1202 | + if( pOut ) sqlite3_str_appendf(pOut, "{\"rid\":%d", rid); | |
| 1203 | 1203 | |
| 1204 | 1204 | /* Basic information about the object. */ |
| 1205 | 1205 | db_prepare(&q, |
| 1206 | 1206 | "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr" |
| 1207 | 1207 | " FROM blob, rcvfrom" |
| @@ -1219,10 +1219,12 @@ | ||
| 1219 | 1219 | db_column_text(&q, 3)); |
| 1220 | 1220 | }else{ |
| 1221 | 1221 | whatis_line(pOut, "artifact","%s", db_column_text(&q,0)); |
| 1222 | 1222 | whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1)); |
| 1223 | 1223 | } |
| 1224 | + }else if( pOut ){ | |
| 1225 | + sqlite3_str_appendf(pOut, ",\"artifact\":null"); | |
| 1224 | 1226 | } |
| 1225 | 1227 | db_finalize(&q); |
| 1226 | 1228 | if( flags & WHATIS_HASHONLY ) return; |
| 1227 | 1229 | |
| 1228 | 1230 | /* Report any symbolic tags on this artifact */ |
| @@ -1240,11 +1242,11 @@ | ||
| 1240 | 1242 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1241 | 1243 | if( pOut ){ |
| 1242 | 1244 | const char *zSep = cnt==0 ? ",tags:[" : ","; |
| 1243 | 1245 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1244 | 1246 | }else{ |
| 1245 | - const char *zPrefix = cnt++ ? ", " : "tags: "; | |
| 1247 | + const char *zPrefix = cnt ? ", " : "tags: "; | |
| 1246 | 1248 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1247 | 1249 | } |
| 1248 | 1250 | cnt++; |
| 1249 | 1251 | } |
| 1250 | 1252 | if( cnt ){ |
| @@ -1270,11 +1272,11 @@ | ||
| 1270 | 1272 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1271 | 1273 | if( pOut ){ |
| 1272 | 1274 | const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ","; |
| 1273 | 1275 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1274 | 1276 | }else{ |
| 1275 | - const char *zPrefix = cnt++ ? ", " : "raw-tags: "; | |
| 1277 | + const char *zPrefix = cnt ? ", " : "raw-tags: "; | |
| 1276 | 1278 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1277 | 1279 | } |
| 1278 | 1280 | cnt++; |
| 1279 | 1281 | } |
| 1280 | 1282 | if( cnt ){ |
| @@ -1411,10 +1413,12 @@ | ||
| 1411 | 1413 | "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))" |
| 1412 | 1414 | " FROM description WHERE rid=%d", rid); |
| 1413 | 1415 | fossil_print("%s\n", zDesc); |
| 1414 | 1416 | fossil_free(zDesc); |
| 1415 | 1417 | } |
| 1418 | + | |
| 1419 | + if( pOut ) sqlite3_str_append(pOut, "}", 1); | |
| 1416 | 1420 | } |
| 1417 | 1421 | |
| 1418 | 1422 | /* |
| 1419 | 1423 | ** Generate a description of artifact from it symbolic name. |
| 1420 | 1424 | */ |
| @@ -1499,11 +1503,11 @@ | ||
| 1499 | 1503 | } |
| 1500 | 1504 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1501 | 1505 | } |
| 1502 | 1506 | db_finalize(&q); |
| 1503 | 1507 | } |
| 1504 | - if( pOut ) sqlite3_str_append(pOut, "]", 1); | |
| 1508 | + if( pOut ) sqlite3_str_append(pOut, "]}", 2); | |
| 1505 | 1509 | }else if( rid==0 ){ |
| 1506 | 1510 | if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){ |
| 1507 | 1511 | /* 0123456789 12 */ |
| 1508 | 1512 | if( zFileName ){ |
| 1509 | 1513 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1510 | 1514 |
| --- 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 |