Fossil SCM

Minor cleanups in the new artifact_to_json() pieces.

stephan 2025-03-24 18:43 trunk
Commit 94d5e322cd7054b7f1479b05593f614cf4a79c1cff1263711a5ce89320dbf179
1 file changed +5 -6
+5 -6
--- src/manifest.c
+++ src/manifest.c
@@ -2914,11 +2914,14 @@
29142914
manifest_crosslink(rid, &content, MC_NONE);
29152915
}
29162916
29172917
/*
29182918
** 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.
29202923
*/
29212924
const char * artifact_type_to_name(int typeId){
29222925
switch(typeId){
29232926
case CFTYPE_MANIFEST: return "checkin";
29242927
case CFTYPE_CLUSTER: return "cluster";
@@ -2943,15 +2946,13 @@
29432946
** instead of having their derived files. If that policy is ever changed,
29442947
** p will need to be non-const.
29452948
*/
29462949
void artifact_to_json(Manifest const *p, Blob *b){
29472950
int i;
2948
- char *zUuid;
29492951
29502952
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));
29532954
/*blob_appendf(b, ", \"rid\": %d", p->rid); not portable across repos*/
29542955
blob_appendf(b, ", \"type\": %!j", artifact_type_to_name(p->type));
29552956
#define ISA(TYPE) if( p->type==TYPE )
29562957
#define CARD_LETTER(LETTER) \
29572958
blob_append_literal(b, ",\"" #LETTER "\": ")
@@ -2965,11 +2966,10 @@
29652966
#define KVP_STR(ADDCOMMA, KEY,VAL) \
29662967
if(ADDCOMMA) blob_append_char(b, ','); \
29672968
blob_appendf(b, "%!j: ", #KEY); \
29682969
STR_OR_NULL(VAL)
29692970
2970
- /* Noting that only 1 (at most) of the A-card pieces will be non-NULL... */
29712971
ISA( CFTYPE_ATTACHMENT ){
29722972
CARD_LETTER(A);
29732973
blob_append_char(b, '{');
29742974
KVP_STR(0, filename, p->zAttachName);
29752975
KVP_STR(1, target, p->zAttachTarget);
@@ -3076,11 +3076,10 @@
30763076
}
30773077
blob_append_char(b, ']');
30783078
}
30793079
CARD_STR2(U, p->zUser);
30803080
CARD_STR2(W, p->zWiki);
3081
- fossil_free(zUuid);
30823081
blob_append_literal(b, "}");
30833082
#undef CARD_FMT
30843083
#undef CARD_LETTER
30853084
#undef CARD_STR
30863085
#undef CARD_STR2
30873086
--- 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

Keyboard Shortcuts

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