Fossil SCM
Add the -pretty flag to test-artifact-to-json.
Commit
479803600c4a261792a4ae8ce094c25510fc5b981dc4f91fa85bbcbce2f84031
Parent
1c248f4de10f91d…
1 file changed
+12
-3
+12
-3
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -2949,25 +2949,34 @@ | ||
| 2949 | 2949 | } |
| 2950 | 2950 | |
| 2951 | 2951 | /* |
| 2952 | 2952 | ** COMMAND: test-artifact-to-json |
| 2953 | 2953 | ** |
| 2954 | -** Usage: %fossil test-artifact-to-json symbolic-name [...names] | |
| 2954 | +** Usage: %fossil test-artifact-to-json ?-pretty? symbolic-name [...names] | |
| 2955 | 2955 | ** |
| 2956 | 2956 | ** Tests the artifact_to_json() and artifact_to_json_by_name() APIs. |
| 2957 | 2957 | */ |
| 2958 | 2958 | void test_manifest_to_json(void){ |
| 2959 | 2959 | int i; |
| 2960 | 2960 | Blob b = empty_blob; |
| 2961 | + Stmt q; | |
| 2962 | + const int bPretty = find_option("pretty",0,0)!=0; | |
| 2961 | 2963 | |
| 2962 | 2964 | db_find_and_open_repository(0,0); |
| 2965 | + db_prepare(&q, "select json_pretty(:json)"); | |
| 2963 | 2966 | for( i=2; i<g.argc; ++i ){ |
| 2964 | 2967 | char const *zName = g.argv[i]; |
| 2965 | 2968 | const int rc = artifact_to_json_by_name(zName, &b); |
| 2966 | 2969 | if( rc<=0 ){ |
| 2967 | 2970 | 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); | |
| 2970 | 2977 | } |
| 2978 | + fossil_print("%b\n", &b); | |
| 2971 | 2979 | blob_reset(&b); |
| 2972 | 2980 | } |
| 2981 | + db_finalize(&q); | |
| 2973 | 2982 | } |
| 2974 | 2983 |
| --- 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 |