Fossil SCM
Minor cleanups in the new artifact_to_json() pieces.
Commit
94d5e322cd7054b7f1479b05593f614cf4a79c1cff1263711a5ce89320dbf179
Parent
26a82dddfe696dd…
1 file changed
+5
-6
+5
-6
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -2914,11 +2914,14 @@ | ||
| 2914 | 2914 | manifest_crosslink(rid, &content, MC_NONE); |
| 2915 | 2915 | } |
| 2916 | 2916 | |
| 2917 | 2917 | /* |
| 2918 | 2918 | ** For a given CATYPE_... value, returns a human-friendly name, or |
| 2919 | -** NULL if typeId is unknown or is CFTYPE_ANY. | |
| 2919 | +** NULL if typeId is unknown or is CFTYPE_ANY. The names returned by | |
| 2920 | +** this function are geared towards use with artifact_to_json(), and | |
| 2921 | +** may differ from some historical uses. e.g. CFTYPE_CONTROL artifacts | |
| 2922 | +** are called "tag" artifacts by this function. | |
| 2920 | 2923 | */ |
| 2921 | 2924 | const char * artifact_type_to_name(int typeId){ |
| 2922 | 2925 | switch(typeId){ |
| 2923 | 2926 | case CFTYPE_MANIFEST: return "checkin"; |
| 2924 | 2927 | case CFTYPE_CLUSTER: return "cluster"; |
| @@ -2943,15 +2946,13 @@ | ||
| 2943 | 2946 | ** instead of having their derived files. If that policy is ever changed, |
| 2944 | 2947 | ** p will need to be non-const. |
| 2945 | 2948 | */ |
| 2946 | 2949 | void artifact_to_json(Manifest const *p, Blob *b){ |
| 2947 | 2950 | int i; |
| 2948 | - char *zUuid; | |
| 2949 | 2951 | |
| 2950 | 2952 | blob_append_literal(b, "{"); |
| 2951 | - zUuid = rid_to_uuid(p->rid); | |
| 2952 | - blob_appendf(b, "\"uuid\": %!j", zUuid); | |
| 2953 | + blob_appendf(b, "\"uuid\": \"%z\"", rid_to_uuid(p->rid)); | |
| 2953 | 2954 | /*blob_appendf(b, ", \"rid\": %d", p->rid); not portable across repos*/ |
| 2954 | 2955 | blob_appendf(b, ", \"type\": %!j", artifact_type_to_name(p->type)); |
| 2955 | 2956 | #define ISA(TYPE) if( p->type==TYPE ) |
| 2956 | 2957 | #define CARD_LETTER(LETTER) \ |
| 2957 | 2958 | blob_append_literal(b, ",\"" #LETTER "\": ") |
| @@ -2965,11 +2966,10 @@ | ||
| 2965 | 2966 | #define KVP_STR(ADDCOMMA, KEY,VAL) \ |
| 2966 | 2967 | if(ADDCOMMA) blob_append_char(b, ','); \ |
| 2967 | 2968 | blob_appendf(b, "%!j: ", #KEY); \ |
| 2968 | 2969 | STR_OR_NULL(VAL) |
| 2969 | 2970 | |
| 2970 | - /* Noting that only 1 (at most) of the A-card pieces will be non-NULL... */ | |
| 2971 | 2971 | ISA( CFTYPE_ATTACHMENT ){ |
| 2972 | 2972 | CARD_LETTER(A); |
| 2973 | 2973 | blob_append_char(b, '{'); |
| 2974 | 2974 | KVP_STR(0, filename, p->zAttachName); |
| 2975 | 2975 | KVP_STR(1, target, p->zAttachTarget); |
| @@ -3076,11 +3076,10 @@ | ||
| 3076 | 3076 | } |
| 3077 | 3077 | blob_append_char(b, ']'); |
| 3078 | 3078 | } |
| 3079 | 3079 | CARD_STR2(U, p->zUser); |
| 3080 | 3080 | CARD_STR2(W, p->zWiki); |
| 3081 | - fossil_free(zUuid); | |
| 3082 | 3081 | blob_append_literal(b, "}"); |
| 3083 | 3082 | #undef CARD_FMT |
| 3084 | 3083 | #undef CARD_LETTER |
| 3085 | 3084 | #undef CARD_STR |
| 3086 | 3085 | #undef CARD_STR2 |
| 3087 | 3086 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -2914,11 +2914,14 @@ | |
| 2914 | manifest_crosslink(rid, &content, MC_NONE); |
| 2915 | } |
| 2916 | |
| 2917 | /* |
| 2918 | ** For a given CATYPE_... value, returns a human-friendly name, or |
| 2919 | ** NULL if typeId is unknown or is CFTYPE_ANY. |
| 2920 | */ |
| 2921 | const char * artifact_type_to_name(int typeId){ |
| 2922 | switch(typeId){ |
| 2923 | case CFTYPE_MANIFEST: return "checkin"; |
| 2924 | case CFTYPE_CLUSTER: return "cluster"; |
| @@ -2943,15 +2946,13 @@ | |
| 2943 | ** instead of having their derived files. If that policy is ever changed, |
| 2944 | ** p will need to be non-const. |
| 2945 | */ |
| 2946 | void artifact_to_json(Manifest const *p, Blob *b){ |
| 2947 | int i; |
| 2948 | char *zUuid; |
| 2949 | |
| 2950 | blob_append_literal(b, "{"); |
| 2951 | zUuid = rid_to_uuid(p->rid); |
| 2952 | blob_appendf(b, "\"uuid\": %!j", zUuid); |
| 2953 | /*blob_appendf(b, ", \"rid\": %d", p->rid); not portable across repos*/ |
| 2954 | blob_appendf(b, ", \"type\": %!j", artifact_type_to_name(p->type)); |
| 2955 | #define ISA(TYPE) if( p->type==TYPE ) |
| 2956 | #define CARD_LETTER(LETTER) \ |
| 2957 | blob_append_literal(b, ",\"" #LETTER "\": ") |
| @@ -2965,11 +2966,10 @@ | |
| 2965 | #define KVP_STR(ADDCOMMA, KEY,VAL) \ |
| 2966 | if(ADDCOMMA) blob_append_char(b, ','); \ |
| 2967 | blob_appendf(b, "%!j: ", #KEY); \ |
| 2968 | STR_OR_NULL(VAL) |
| 2969 | |
| 2970 | /* Noting that only 1 (at most) of the A-card pieces will be non-NULL... */ |
| 2971 | ISA( CFTYPE_ATTACHMENT ){ |
| 2972 | CARD_LETTER(A); |
| 2973 | blob_append_char(b, '{'); |
| 2974 | KVP_STR(0, filename, p->zAttachName); |
| 2975 | KVP_STR(1, target, p->zAttachTarget); |
| @@ -3076,11 +3076,10 @@ | |
| 3076 | } |
| 3077 | blob_append_char(b, ']'); |
| 3078 | } |
| 3079 | CARD_STR2(U, p->zUser); |
| 3080 | CARD_STR2(W, p->zWiki); |
| 3081 | fossil_free(zUuid); |
| 3082 | blob_append_literal(b, "}"); |
| 3083 | #undef CARD_FMT |
| 3084 | #undef CARD_LETTER |
| 3085 | #undef CARD_STR |
| 3086 | #undef CARD_STR2 |
| 3087 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -2914,11 +2914,14 @@ | |
| 2914 | manifest_crosslink(rid, &content, MC_NONE); |
| 2915 | } |
| 2916 | |
| 2917 | /* |
| 2918 | ** For a given CATYPE_... value, returns a human-friendly name, or |
| 2919 | ** NULL if typeId is unknown or is CFTYPE_ANY. The names returned by |
| 2920 | ** this function are geared towards use with artifact_to_json(), and |
| 2921 | ** may differ from some historical uses. e.g. CFTYPE_CONTROL artifacts |
| 2922 | ** are called "tag" artifacts by this function. |
| 2923 | */ |
| 2924 | const char * artifact_type_to_name(int typeId){ |
| 2925 | switch(typeId){ |
| 2926 | case CFTYPE_MANIFEST: return "checkin"; |
| 2927 | case CFTYPE_CLUSTER: return "cluster"; |
| @@ -2943,15 +2946,13 @@ | |
| 2946 | ** instead of having their derived files. If that policy is ever changed, |
| 2947 | ** p will need to be non-const. |
| 2948 | */ |
| 2949 | void artifact_to_json(Manifest const *p, Blob *b){ |
| 2950 | int i; |
| 2951 | |
| 2952 | blob_append_literal(b, "{"); |
| 2953 | blob_appendf(b, "\"uuid\": \"%z\"", rid_to_uuid(p->rid)); |
| 2954 | /*blob_appendf(b, ", \"rid\": %d", p->rid); not portable across repos*/ |
| 2955 | blob_appendf(b, ", \"type\": %!j", artifact_type_to_name(p->type)); |
| 2956 | #define ISA(TYPE) if( p->type==TYPE ) |
| 2957 | #define CARD_LETTER(LETTER) \ |
| 2958 | blob_append_literal(b, ",\"" #LETTER "\": ") |
| @@ -2965,11 +2966,10 @@ | |
| 2966 | #define KVP_STR(ADDCOMMA, KEY,VAL) \ |
| 2967 | if(ADDCOMMA) blob_append_char(b, ','); \ |
| 2968 | blob_appendf(b, "%!j: ", #KEY); \ |
| 2969 | STR_OR_NULL(VAL) |
| 2970 | |
| 2971 | ISA( CFTYPE_ATTACHMENT ){ |
| 2972 | CARD_LETTER(A); |
| 2973 | blob_append_char(b, '{'); |
| 2974 | KVP_STR(0, filename, p->zAttachName); |
| 2975 | KVP_STR(1, target, p->zAttachTarget); |
| @@ -3076,11 +3076,10 @@ | |
| 3076 | } |
| 3077 | blob_append_char(b, ']'); |
| 3078 | } |
| 3079 | CARD_STR2(U, p->zUser); |
| 3080 | CARD_STR2(W, p->zWiki); |
| 3081 | blob_append_literal(b, "}"); |
| 3082 | #undef CARD_FMT |
| 3083 | #undef CARD_LETTER |
| 3084 | #undef CARD_STR |
| 3085 | #undef CARD_STR2 |
| 3086 |