Fossil SCM
refactored json_artifact_file() a bit to re-use other code.
Commit
a4f4c62a1a7334a98a03de1b4a008462ff4100ff
Parent
4f196f15fb842f9…
1 file changed
+37
-26
+37
-26
| --- src/json_artifact.c | ||
| +++ src/json_artifact.c | ||
| @@ -232,57 +232,68 @@ | ||
| 232 | 232 | zMime = mimetype_from_content(&content); |
| 233 | 233 | |
| 234 | 234 | if (!zMime){ |
| 235 | 235 | cson_array * checkin_arr = NULL; |
| 236 | 236 | cson_value * checkin_list = NULL; |
| 237 | - | |
| 237 | + /*cson_string * tagKey = NULL;*/ | |
| 238 | 238 | cson_value * checkinV = NULL; |
| 239 | 239 | cson_object * checkin = NULL; |
| 240 | 240 | |
| 241 | + cson_int_t const rawLen = blob_size(&content); | |
| 241 | 242 | zRaw = blob_str(&content); |
| 242 | 243 | checkin_list = cson_value_new_array(); |
| 243 | 244 | |
| 244 | - cson_object_set(pay, "content", json_new_string(zRaw)); | |
| 245 | + cson_object_set(pay, "contentLength", | |
| 246 | + json_new_int( rawLen | |
| 247 | + /* achtung: overflow potential on 32-bit builds! */)); | |
| 248 | + cson_object_set(pay, "content", | |
| 249 | + cson_value_new_string(zRaw,(unsigned int)rawLen)); | |
| 245 | 250 | cson_object_set(pay, "checkins", checkin_list); |
| 246 | 251 | |
| 247 | 252 | checkin_arr = cson_value_get_array(checkin_list); |
| 248 | 253 | |
| 249 | 254 | db_prepare(&q, |
| 250 | - "SELECT filename.name, datetime(event.mtime)," | |
| 251 | - " coalesce(event.ecomment,event.comment)," | |
| 252 | - " coalesce(event.euser,event.user)," | |
| 253 | - " b.uuid, mlink.mperm," | |
| 255 | + "SELECT filename.name AS name, " | |
| 256 | + " cast(strftime('%%s',event.mtime) as int) AS mtime," | |
| 257 | + " coalesce(event.ecomment,event.comment) as comment," | |
| 258 | + " coalesce(event.euser,event.user) as user," | |
| 259 | + " b.uuid as uuid, mlink.mperm as wtf1," | |
| 254 | 260 | " coalesce((SELECT value FROM tagxref" |
| 255 | - " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')" | |
| 261 | + " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk') as branch" | |
| 256 | 262 | " FROM mlink, filename, event, blob a, blob b" |
| 257 | 263 | " WHERE filename.fnid=mlink.fnid" |
| 258 | 264 | " AND event.objid=mlink.mid" |
| 259 | 265 | " AND a.rid=mlink.fid" |
| 260 | 266 | " AND b.rid=mlink.mid" |
| 261 | 267 | " AND mlink.fid=%d" |
| 262 | 268 | " ORDER BY filename.name, event.mtime", |
| 263 | 269 | TAG_BRANCH, rid |
| 264 | 270 | ); |
| 265 | - | |
| 266 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 267 | - const char *zName = db_column_text(&q, 0); | |
| 268 | - const char *zDate = db_column_text(&q, 1); | |
| 269 | - const char *zCom = db_column_text(&q, 2); | |
| 270 | - const char *zUser = db_column_text(&q, 3); | |
| 271 | - const char *zVers = db_column_text(&q, 4); | |
| 272 | - | |
| 273 | - checkinV = cson_value_new_object(); | |
| 274 | - checkin = cson_value_get_object(checkinV); | |
| 275 | - | |
| 276 | - cson_object_set(checkin, "name", json_new_string(zName)); | |
| 277 | - cson_object_set(checkin, "date", json_new_string(zDate)); | |
| 278 | - cson_object_set(checkin, "comment", json_new_string(zCom)); | |
| 279 | - cson_object_set(checkin, "user", json_new_string(zUser)); | |
| 280 | - cson_object_set(checkin, "version", json_new_string(zVers)); | |
| 281 | - | |
| 282 | - cson_array_append(checkin_arr, checkinV); | |
| 283 | - } | |
| 271 | +#if 0 | |
| 272 | + /* Damn: json_tags_for_rid() only works for commits. | |
| 273 | + | |
| 274 | + FIXME: extend json_tags_for_rid() to accept file rids and then | |
| 275 | + implement this loop to add the tags to each object. | |
| 276 | + */ | |
| 277 | + | |
| 278 | + while( SQLITE_ROW == db_step(&q) ){ | |
| 279 | + checkinV = cson_sqlite3_row_to_object( q.pStmt ); | |
| 280 | + if(!checkinV){ | |
| 281 | + continue; | |
| 282 | + } | |
| 283 | + if(!tagKey) { | |
| 284 | + tagKey = cson_new_string("tags",4); | |
| 285 | + json_gc_add("artifact/file/tags", cson_string_value(tagKey)) | |
| 286 | + /*avoids a potential lifetime issue*/; | |
| 287 | + } | |
| 288 | + checkin = cson_value_get_object(checkinV); | |
| 289 | + cson_object_set_s(checkin, tagKey, json_tags_for_rid(rid,0)); | |
| 290 | + cson_array_append( checkin_arr, checkinV ); | |
| 291 | + } | |
| 292 | +#else | |
| 293 | + json_stmt_to_array_of_obj( &q, checkin_list ); | |
| 294 | +#endif | |
| 284 | 295 | db_finalize(&q); |
| 285 | 296 | } |
| 286 | 297 | return payV; |
| 287 | 298 | } |
| 288 | 299 | |
| 289 | 300 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -232,57 +232,68 @@ | |
| 232 | zMime = mimetype_from_content(&content); |
| 233 | |
| 234 | if (!zMime){ |
| 235 | cson_array * checkin_arr = NULL; |
| 236 | cson_value * checkin_list = NULL; |
| 237 | |
| 238 | cson_value * checkinV = NULL; |
| 239 | cson_object * checkin = NULL; |
| 240 | |
| 241 | zRaw = blob_str(&content); |
| 242 | checkin_list = cson_value_new_array(); |
| 243 | |
| 244 | cson_object_set(pay, "content", json_new_string(zRaw)); |
| 245 | cson_object_set(pay, "checkins", checkin_list); |
| 246 | |
| 247 | checkin_arr = cson_value_get_array(checkin_list); |
| 248 | |
| 249 | db_prepare(&q, |
| 250 | "SELECT filename.name, datetime(event.mtime)," |
| 251 | " coalesce(event.ecomment,event.comment)," |
| 252 | " coalesce(event.euser,event.user)," |
| 253 | " b.uuid, mlink.mperm," |
| 254 | " coalesce((SELECT value FROM tagxref" |
| 255 | " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')" |
| 256 | " FROM mlink, filename, event, blob a, blob b" |
| 257 | " WHERE filename.fnid=mlink.fnid" |
| 258 | " AND event.objid=mlink.mid" |
| 259 | " AND a.rid=mlink.fid" |
| 260 | " AND b.rid=mlink.mid" |
| 261 | " AND mlink.fid=%d" |
| 262 | " ORDER BY filename.name, event.mtime", |
| 263 | TAG_BRANCH, rid |
| 264 | ); |
| 265 | |
| 266 | while( db_step(&q)==SQLITE_ROW ){ |
| 267 | const char *zName = db_column_text(&q, 0); |
| 268 | const char *zDate = db_column_text(&q, 1); |
| 269 | const char *zCom = db_column_text(&q, 2); |
| 270 | const char *zUser = db_column_text(&q, 3); |
| 271 | const char *zVers = db_column_text(&q, 4); |
| 272 | |
| 273 | checkinV = cson_value_new_object(); |
| 274 | checkin = cson_value_get_object(checkinV); |
| 275 | |
| 276 | cson_object_set(checkin, "name", json_new_string(zName)); |
| 277 | cson_object_set(checkin, "date", json_new_string(zDate)); |
| 278 | cson_object_set(checkin, "comment", json_new_string(zCom)); |
| 279 | cson_object_set(checkin, "user", json_new_string(zUser)); |
| 280 | cson_object_set(checkin, "version", json_new_string(zVers)); |
| 281 | |
| 282 | cson_array_append(checkin_arr, checkinV); |
| 283 | } |
| 284 | db_finalize(&q); |
| 285 | } |
| 286 | return payV; |
| 287 | } |
| 288 | |
| 289 |
| --- src/json_artifact.c | |
| +++ src/json_artifact.c | |
| @@ -232,57 +232,68 @@ | |
| 232 | zMime = mimetype_from_content(&content); |
| 233 | |
| 234 | if (!zMime){ |
| 235 | cson_array * checkin_arr = NULL; |
| 236 | cson_value * checkin_list = NULL; |
| 237 | /*cson_string * tagKey = NULL;*/ |
| 238 | cson_value * checkinV = NULL; |
| 239 | cson_object * checkin = NULL; |
| 240 | |
| 241 | cson_int_t const rawLen = blob_size(&content); |
| 242 | zRaw = blob_str(&content); |
| 243 | checkin_list = cson_value_new_array(); |
| 244 | |
| 245 | cson_object_set(pay, "contentLength", |
| 246 | json_new_int( rawLen |
| 247 | /* achtung: overflow potential on 32-bit builds! */)); |
| 248 | cson_object_set(pay, "content", |
| 249 | cson_value_new_string(zRaw,(unsigned int)rawLen)); |
| 250 | cson_object_set(pay, "checkins", checkin_list); |
| 251 | |
| 252 | checkin_arr = cson_value_get_array(checkin_list); |
| 253 | |
| 254 | db_prepare(&q, |
| 255 | "SELECT filename.name AS name, " |
| 256 | " cast(strftime('%%s',event.mtime) as int) AS mtime," |
| 257 | " coalesce(event.ecomment,event.comment) as comment," |
| 258 | " coalesce(event.euser,event.user) as user," |
| 259 | " b.uuid as uuid, mlink.mperm as wtf1," |
| 260 | " coalesce((SELECT value FROM tagxref" |
| 261 | " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk') as branch" |
| 262 | " FROM mlink, filename, event, blob a, blob b" |
| 263 | " WHERE filename.fnid=mlink.fnid" |
| 264 | " AND event.objid=mlink.mid" |
| 265 | " AND a.rid=mlink.fid" |
| 266 | " AND b.rid=mlink.mid" |
| 267 | " AND mlink.fid=%d" |
| 268 | " ORDER BY filename.name, event.mtime", |
| 269 | TAG_BRANCH, rid |
| 270 | ); |
| 271 | #if 0 |
| 272 | /* Damn: json_tags_for_rid() only works for commits. |
| 273 | |
| 274 | FIXME: extend json_tags_for_rid() to accept file rids and then |
| 275 | implement this loop to add the tags to each object. |
| 276 | */ |
| 277 | |
| 278 | while( SQLITE_ROW == db_step(&q) ){ |
| 279 | checkinV = cson_sqlite3_row_to_object( q.pStmt ); |
| 280 | if(!checkinV){ |
| 281 | continue; |
| 282 | } |
| 283 | if(!tagKey) { |
| 284 | tagKey = cson_new_string("tags",4); |
| 285 | json_gc_add("artifact/file/tags", cson_string_value(tagKey)) |
| 286 | /*avoids a potential lifetime issue*/; |
| 287 | } |
| 288 | checkin = cson_value_get_object(checkinV); |
| 289 | cson_object_set_s(checkin, tagKey, json_tags_for_rid(rid,0)); |
| 290 | cson_array_append( checkin_arr, checkinV ); |
| 291 | } |
| 292 | #else |
| 293 | json_stmt_to_array_of_obj( &q, checkin_list ); |
| 294 | #endif |
| 295 | db_finalize(&q); |
| 296 | } |
| 297 | return payV; |
| 298 | } |
| 299 | |
| 300 |