Fossil SCM
/json/timeline/checkin: changed response payload to include "parents" array property with UUIDs of all parents, removing the parentUuid property which just referenced the primary parent. The first parent in the array is the primary parent. Thanks go to Brian Smith for catching this oversight.
Commit
0c9c99b83f936b44fd6c5d0ee5a308b48097e99f
Parent
ef561ed0a56a45a…
1 file changed
+48
-13
+48
-13
| --- src/json_artifact.c | ||
| +++ src/json_artifact.c | ||
| @@ -48,31 +48,49 @@ | ||
| 48 | 48 | payload.artifact property of /json/artifact responses. |
| 49 | 49 | */ |
| 50 | 50 | artifact_f func; |
| 51 | 51 | } ArtifactDispatchEntry; |
| 52 | 52 | |
| 53 | + | |
| 54 | +/* | |
| 55 | +** Generates a JSON Array reference holding the parent UUIDs (as strings). | |
| 56 | +** If it finds no matches then it returns NULL (OOM is a fatal error). | |
| 57 | +** | |
| 58 | +** Returned value is NULL or an Array owned by the caller. | |
| 59 | +*/ | |
| 60 | +cson_value * json_parent_uuids_for_ci( int rid ){ | |
| 61 | + Stmt q = empty_Stmt; | |
| 62 | + cson_array * pParents = NULL; | |
| 63 | + db_prepare( &q, | |
| 64 | + "SELECT uuid FROM plink, blob" | |
| 65 | + " WHERE plink.cid=%d AND blob.rid=plink.pid" | |
| 66 | + " ORDER BY plink.isprim DESC", | |
| 67 | + rid ); | |
| 68 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 69 | + if(!pParents) { | |
| 70 | + pParents = cson_new_array(); | |
| 71 | + } | |
| 72 | + cson_array_append( pParents, cson_sqlite3_column_to_value( q.pStmt, 0 ) ); | |
| 73 | + } | |
| 74 | + db_finalize(&q); | |
| 75 | + return cson_array_value(pParents); | |
| 76 | +} | |
| 53 | 77 | |
| 54 | 78 | /* |
| 55 | 79 | ** Generates an artifact Object for the given rid, |
| 56 | 80 | ** which must refer to a Checkin. |
| 57 | 81 | ** |
| 58 | 82 | ** Returned value is NULL or an Object owned by the caller. |
| 59 | 83 | */ |
| 60 | 84 | cson_value * json_artifact_for_ci( int rid, char showFiles ){ |
| 61 | - char * zParent = NULL; | |
| 62 | 85 | cson_value * v = NULL; |
| 63 | 86 | Stmt q; |
| 64 | 87 | static cson_value * eventTypeLabel = NULL; |
| 65 | 88 | if(!eventTypeLabel){ |
| 66 | 89 | eventTypeLabel = json_new_string("checkin"); |
| 67 | 90 | json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel); |
| 68 | 91 | } |
| 69 | - zParent = db_text(0, | |
| 70 | - "SELECT uuid FROM plink, blob" | |
| 71 | - " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim", | |
| 72 | - rid | |
| 73 | - ); | |
| 74 | 92 | |
| 75 | 93 | db_prepare(&q, |
| 76 | 94 | "SELECT uuid, " |
| 77 | 95 | " cast(strftime('%%s',mtime) as int), " |
| 78 | 96 | " user, " |
| @@ -88,10 +106,14 @@ | ||
| 88 | 106 | cson_value * tmpV = NULL; |
| 89 | 107 | const char *zUuid = db_column_text(&q, 0); |
| 90 | 108 | const char *zUser; |
| 91 | 109 | const char *zComment; |
| 92 | 110 | char * zEUser, * zEComment; |
| 111 | +#define ADD_PRIMARY_PARENT_UUID 0 /* temporary local macro */ | |
| 112 | +#if ADD_PRIMARY_PARENT_UUID | |
| 113 | + char * zParent = NULL; | |
| 114 | +#endif | |
| 93 | 115 | int mtime, omtime; |
| 94 | 116 | v = cson_value_new_object(); |
| 95 | 117 | o = cson_value_get_object(v); |
| 96 | 118 | #define SET(K,V) cson_object_set(o,(K), (V)) |
| 97 | 119 | SET("type", eventTypeLabel ); |
| @@ -130,30 +152,43 @@ | ||
| 130 | 152 | omtime = db_column_int(&q,4); |
| 131 | 153 | if(omtime && (omtime!=mtime)){ |
| 132 | 154 | SET("originTime",json_new_int(omtime)); |
| 133 | 155 | } |
| 134 | 156 | |
| 135 | - if(zParent){ | |
| 136 | - SET("parentUuid", json_new_string(zParent)); | |
| 157 | +#if ADD_PRIMARY_PARENT_UUID | |
| 158 | + zParent = db_text(0, | |
| 159 | + "SELECT uuid FROM plink, blob" | |
| 160 | + " WHERE plink.cid=%d AND blob.rid=plink.pid" | |
| 161 | + " AND plink.isprim", | |
| 162 | + rid | |
| 163 | + ); | |
| 164 | + tmpV = zParent ? json_new_string(zParent) : cson_value_null(); | |
| 165 | + free(zParent); | |
| 166 | + zParent = NULL; | |
| 167 | + SET("parentUuid", tmpV ); | |
| 168 | +#endif | |
| 169 | +#undef ADD_PRIMARY_PARENT_UUID | |
| 170 | + | |
| 171 | + tmpV = json_parent_uuids_for_ci(rid); | |
| 172 | + if(tmpV){ | |
| 173 | + SET("parents", tmpV); | |
| 137 | 174 | } |
| 138 | 175 | |
| 139 | 176 | tmpV = json_tags_for_checkin_rid(rid,0); |
| 140 | 177 | if(tmpV){ |
| 141 | 178 | SET("tags",tmpV); |
| 142 | 179 | } |
| 143 | 180 | |
| 144 | 181 | if( showFiles ){ |
| 145 | - cson_value * fileList = json_get_changed_files(rid); | |
| 146 | - if(fileList){ | |
| 147 | - SET("files",fileList); | |
| 182 | + tmpV = json_get_changed_files(rid); | |
| 183 | + if(tmpV){ | |
| 184 | + SET("files",tmpV); | |
| 148 | 185 | } |
| 149 | 186 | } |
| 150 | 187 | |
| 151 | - | |
| 152 | 188 | #undef SET |
| 153 | 189 | } |
| 154 | - free(zParent); | |
| 155 | 190 | db_finalize(&q); |
| 156 | 191 | return v; |
| 157 | 192 | } |
| 158 | 193 | |
| 159 | 194 | /* |
| 160 | 195 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -48,31 +48,49 @@ | |
| 48 | payload.artifact property of /json/artifact responses. |
| 49 | */ |
| 50 | artifact_f func; |
| 51 | } ArtifactDispatchEntry; |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | ** Generates an artifact Object for the given rid, |
| 56 | ** which must refer to a Checkin. |
| 57 | ** |
| 58 | ** Returned value is NULL or an Object owned by the caller. |
| 59 | */ |
| 60 | cson_value * json_artifact_for_ci( int rid, char showFiles ){ |
| 61 | char * zParent = NULL; |
| 62 | cson_value * v = NULL; |
| 63 | Stmt q; |
| 64 | static cson_value * eventTypeLabel = NULL; |
| 65 | if(!eventTypeLabel){ |
| 66 | eventTypeLabel = json_new_string("checkin"); |
| 67 | json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel); |
| 68 | } |
| 69 | zParent = db_text(0, |
| 70 | "SELECT uuid FROM plink, blob" |
| 71 | " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim", |
| 72 | rid |
| 73 | ); |
| 74 | |
| 75 | db_prepare(&q, |
| 76 | "SELECT uuid, " |
| 77 | " cast(strftime('%%s',mtime) as int), " |
| 78 | " user, " |
| @@ -88,10 +106,14 @@ | |
| 88 | cson_value * tmpV = NULL; |
| 89 | const char *zUuid = db_column_text(&q, 0); |
| 90 | const char *zUser; |
| 91 | const char *zComment; |
| 92 | char * zEUser, * zEComment; |
| 93 | int mtime, omtime; |
| 94 | v = cson_value_new_object(); |
| 95 | o = cson_value_get_object(v); |
| 96 | #define SET(K,V) cson_object_set(o,(K), (V)) |
| 97 | SET("type", eventTypeLabel ); |
| @@ -130,30 +152,43 @@ | |
| 130 | omtime = db_column_int(&q,4); |
| 131 | if(omtime && (omtime!=mtime)){ |
| 132 | SET("originTime",json_new_int(omtime)); |
| 133 | } |
| 134 | |
| 135 | if(zParent){ |
| 136 | SET("parentUuid", json_new_string(zParent)); |
| 137 | } |
| 138 | |
| 139 | tmpV = json_tags_for_checkin_rid(rid,0); |
| 140 | if(tmpV){ |
| 141 | SET("tags",tmpV); |
| 142 | } |
| 143 | |
| 144 | if( showFiles ){ |
| 145 | cson_value * fileList = json_get_changed_files(rid); |
| 146 | if(fileList){ |
| 147 | SET("files",fileList); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | |
| 152 | #undef SET |
| 153 | } |
| 154 | free(zParent); |
| 155 | db_finalize(&q); |
| 156 | return v; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -48,31 +48,49 @@ | |
| 48 | payload.artifact property of /json/artifact responses. |
| 49 | */ |
| 50 | artifact_f func; |
| 51 | } ArtifactDispatchEntry; |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | ** Generates a JSON Array reference holding the parent UUIDs (as strings). |
| 56 | ** If it finds no matches then it returns NULL (OOM is a fatal error). |
| 57 | ** |
| 58 | ** Returned value is NULL or an Array owned by the caller. |
| 59 | */ |
| 60 | cson_value * json_parent_uuids_for_ci( int rid ){ |
| 61 | Stmt q = empty_Stmt; |
| 62 | cson_array * pParents = NULL; |
| 63 | db_prepare( &q, |
| 64 | "SELECT uuid FROM plink, blob" |
| 65 | " WHERE plink.cid=%d AND blob.rid=plink.pid" |
| 66 | " ORDER BY plink.isprim DESC", |
| 67 | rid ); |
| 68 | while( SQLITE_ROW==db_step(&q) ){ |
| 69 | if(!pParents) { |
| 70 | pParents = cson_new_array(); |
| 71 | } |
| 72 | cson_array_append( pParents, cson_sqlite3_column_to_value( q.pStmt, 0 ) ); |
| 73 | } |
| 74 | db_finalize(&q); |
| 75 | return cson_array_value(pParents); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | ** Generates an artifact Object for the given rid, |
| 80 | ** which must refer to a Checkin. |
| 81 | ** |
| 82 | ** Returned value is NULL or an Object owned by the caller. |
| 83 | */ |
| 84 | cson_value * json_artifact_for_ci( int rid, char showFiles ){ |
| 85 | cson_value * v = NULL; |
| 86 | Stmt q; |
| 87 | static cson_value * eventTypeLabel = NULL; |
| 88 | if(!eventTypeLabel){ |
| 89 | eventTypeLabel = json_new_string("checkin"); |
| 90 | json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel); |
| 91 | } |
| 92 | |
| 93 | db_prepare(&q, |
| 94 | "SELECT uuid, " |
| 95 | " cast(strftime('%%s',mtime) as int), " |
| 96 | " user, " |
| @@ -88,10 +106,14 @@ | |
| 106 | cson_value * tmpV = NULL; |
| 107 | const char *zUuid = db_column_text(&q, 0); |
| 108 | const char *zUser; |
| 109 | const char *zComment; |
| 110 | char * zEUser, * zEComment; |
| 111 | #define ADD_PRIMARY_PARENT_UUID 0 /* temporary local macro */ |
| 112 | #if ADD_PRIMARY_PARENT_UUID |
| 113 | char * zParent = NULL; |
| 114 | #endif |
| 115 | int mtime, omtime; |
| 116 | v = cson_value_new_object(); |
| 117 | o = cson_value_get_object(v); |
| 118 | #define SET(K,V) cson_object_set(o,(K), (V)) |
| 119 | SET("type", eventTypeLabel ); |
| @@ -130,30 +152,43 @@ | |
| 152 | omtime = db_column_int(&q,4); |
| 153 | if(omtime && (omtime!=mtime)){ |
| 154 | SET("originTime",json_new_int(omtime)); |
| 155 | } |
| 156 | |
| 157 | #if ADD_PRIMARY_PARENT_UUID |
| 158 | zParent = db_text(0, |
| 159 | "SELECT uuid FROM plink, blob" |
| 160 | " WHERE plink.cid=%d AND blob.rid=plink.pid" |
| 161 | " AND plink.isprim", |
| 162 | rid |
| 163 | ); |
| 164 | tmpV = zParent ? json_new_string(zParent) : cson_value_null(); |
| 165 | free(zParent); |
| 166 | zParent = NULL; |
| 167 | SET("parentUuid", tmpV ); |
| 168 | #endif |
| 169 | #undef ADD_PRIMARY_PARENT_UUID |
| 170 | |
| 171 | tmpV = json_parent_uuids_for_ci(rid); |
| 172 | if(tmpV){ |
| 173 | SET("parents", tmpV); |
| 174 | } |
| 175 | |
| 176 | tmpV = json_tags_for_checkin_rid(rid,0); |
| 177 | if(tmpV){ |
| 178 | SET("tags",tmpV); |
| 179 | } |
| 180 | |
| 181 | if( showFiles ){ |
| 182 | tmpV = json_get_changed_files(rid); |
| 183 | if(tmpV){ |
| 184 | SET("files",tmpV); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | #undef SET |
| 189 | } |
| 190 | db_finalize(&q); |
| 191 | return v; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 |