Fossil SCM

Add the -pretty flag to test-artifact-to-json.

stephan 2025-03-24 12:25 artifact-to-json
Commit 479803600c4a261792a4ae8ce094c25510fc5b981dc4f91fa85bbcbce2f84031
1 file changed +12 -3
+12 -3
--- src/manifest.c
+++ src/manifest.c
@@ -2949,25 +2949,34 @@
29492949
}
29502950
29512951
/*
29522952
** COMMAND: test-artifact-to-json
29532953
**
2954
-** Usage: %fossil test-artifact-to-json symbolic-name [...names]
2954
+** Usage: %fossil test-artifact-to-json ?-pretty? symbolic-name [...names]
29552955
**
29562956
** Tests the artifact_to_json() and artifact_to_json_by_name() APIs.
29572957
*/
29582958
void test_manifest_to_json(void){
29592959
int i;
29602960
Blob b = empty_blob;
2961
+ Stmt q;
2962
+ const int bPretty = find_option("pretty",0,0)!=0;
29612963
29622964
db_find_and_open_repository(0,0);
2965
+ db_prepare(&q, "select json_pretty(:json)");
29632966
for( i=2; i<g.argc; ++i ){
29642967
char const *zName = g.argv[i];
29652968
const int rc = artifact_to_json_by_name(zName, &b);
29662969
if( rc<=0 ){
29672970
fossil_warning("Error reading artifact %Q\n", zName);
2968
- }else{
2969
- fossil_print("%b\n", &b);
2971
+ }else if( bPretty ){
2972
+ db_bind_blob(&q, ":json", &b);
2973
+ b.nUsed = 0;
2974
+ db_step(&q);
2975
+ db_column_blob(&q, 0, &b);
2976
+ db_reset(&q);
29702977
}
2978
+ fossil_print("%b\n", &b);
29712979
blob_reset(&b);
29722980
}
2981
+ db_finalize(&q);
29732982
}
29742983
--- src/manifest.c
+++ src/manifest.c
@@ -2949,25 +2949,34 @@
2949 }
2950
2951 /*
2952 ** COMMAND: test-artifact-to-json
2953 **
2954 ** Usage: %fossil test-artifact-to-json symbolic-name [...names]
2955 **
2956 ** Tests the artifact_to_json() and artifact_to_json_by_name() APIs.
2957 */
2958 void test_manifest_to_json(void){
2959 int i;
2960 Blob b = empty_blob;
 
 
2961
2962 db_find_and_open_repository(0,0);
 
2963 for( i=2; i<g.argc; ++i ){
2964 char const *zName = g.argv[i];
2965 const int rc = artifact_to_json_by_name(zName, &b);
2966 if( rc<=0 ){
2967 fossil_warning("Error reading artifact %Q\n", zName);
2968 }else{
2969 fossil_print("%b\n", &b);
 
 
 
 
2970 }
 
2971 blob_reset(&b);
2972 }
 
2973 }
2974
--- src/manifest.c
+++ src/manifest.c
@@ -2949,25 +2949,34 @@
2949 }
2950
2951 /*
2952 ** COMMAND: test-artifact-to-json
2953 **
2954 ** Usage: %fossil test-artifact-to-json ?-pretty? symbolic-name [...names]
2955 **
2956 ** Tests the artifact_to_json() and artifact_to_json_by_name() APIs.
2957 */
2958 void test_manifest_to_json(void){
2959 int i;
2960 Blob b = empty_blob;
2961 Stmt q;
2962 const int bPretty = find_option("pretty",0,0)!=0;
2963
2964 db_find_and_open_repository(0,0);
2965 db_prepare(&q, "select json_pretty(:json)");
2966 for( i=2; i<g.argc; ++i ){
2967 char const *zName = g.argv[i];
2968 const int rc = artifact_to_json_by_name(zName, &b);
2969 if( rc<=0 ){
2970 fossil_warning("Error reading artifact %Q\n", zName);
2971 }else if( bPretty ){
2972 db_bind_blob(&q, ":json", &b);
2973 b.nUsed = 0;
2974 db_step(&q);
2975 db_column_blob(&q, 0, &b);
2976 db_reset(&q);
2977 }
2978 fossil_print("%b\n", &b);
2979 blob_reset(&b);
2980 }
2981 db_finalize(&q);
2982 }
2983

Keyboard Shortcuts

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