Fossil SCM

Changes to how /json/(artifact|finfo|timeline) handle file content and modification-state flag. Some API-incompatible changes.

stephan 2012-03-22 22:09 trunk
Commit 8c6dc243c912e3e0bc2df8df2b14511939042975
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -248,15 +248,30 @@
248248
contentFormat = json_artifact_include_content_flag() ? -1 : 0;
249249
}
250250
return json_get_wiki_page_by_rid(rid, contentFormat);
251251
}
252252
}
253
+
254
+/*
255
+** Internal helper for routines which add a "status" flag to file
256
+** artifact data. isNew and isDel should be the "is this object new?"
257
+** and "is this object removed?" flags of the underlying query. This
258
+** function returns a static string from the set (added, removed,
259
+** modified), depending on the combination of the two args.
260
+**
261
+** Reminder to self: (mlink.pid==0) AS isNew, (mlink.fid==0) AS isDel
262
+*/
263
+char const * json_artifact_status_to_string( char isNew, char isDel ){
264
+ return isNew
265
+ ? "added"
266
+ : (isDel
267
+ ? "removed"
268
+ : "modified");
269
+}
253270
254271
cson_value * json_artifact_file(int rid){
255272
cson_object * pay = NULL;
256
- const char *zMime;
257
- Blob content = empty_blob;
258273
Stmt q = empty_Stmt;
259274
cson_array * checkin_arr = NULL;
260275
261276
if( ! g.perm.Read ){
262277
json_set_err(FSL_JSON_E_DENIED,
@@ -264,35 +279,39 @@
264279
return NULL;
265280
}
266281
267282
pay = cson_new_object();
268283
269
- content_get(rid, &content);
270
- cson_object_set(pay, "contentLength",
271
- json_new_int( blob_size(&content) )
272
- /* achtung: overflow potential on 32-bit builds! */);
273
- zMime = mimetype_from_content(&content);
274
-
275
- cson_object_set(pay, "contentType",
276
- json_new_string(zMime ? zMime : "text/plain"));
277
- if( json_artifact_include_content_flag() && !zMime ){
284
+ if( json_artifact_include_content_flag() ){
285
+ Blob content = empty_blob;
286
+ const char *zMime;
287
+ content_get(rid, &content);
288
+ zMime = mimetype_from_content(&content);
289
+ cson_object_set(pay, "contentType",
290
+ json_new_string(zMime ? zMime : "text/plain"));
291
+ cson_object_set(pay, "size", json_new_int( blob_size(&content)) );
292
+ if(!zMime){
278293
cson_object_set(pay, "content",
279294
cson_value_new_string(blob_str(&content),
280295
(unsigned int)blob_size(&content)));
296
+ }
297
+ blob_reset(&content);
281298
}
282
- blob_reset(&content);
283299
284300
db_prepare(&q,
285301
"SELECT filename.name AS name, "
286
- " cast(strftime('%%s',event.mtime) as int) AS timestamp,"
287
- " coalesce(event.ecomment,event.comment) as comment,"
288
- " coalesce(event.euser,event.user) as user,"
289
- " b.uuid as uuid, "
302
+ " (mlink.pid==0) AS isNew,"
303
+ " (mlink.fid==0) AS isDel,"
304
+ " cast(strftime('%%s',event.mtime) as int) AS timestamp,"
305
+ " coalesce(event.ecomment,event.comment) as comment,"
306
+ " coalesce(event.euser,event.user) as user,"
307
+ " a.size AS size,"
308
+ " b.uuid as uuid, "
290309
#if 0
291
- " mlink.mperm as mperm,"
310
+ " mlink.mperm as mperm,"
292311
#endif
293
- " coalesce((SELECT value FROM tagxref"
312
+ " coalesce((SELECT value FROM tagxref"
294313
" WHERE tagid=%d AND tagtype>0 AND "
295314
" rid=mlink.mid),'trunk') as branch"
296315
" FROM mlink, filename, event, blob a, blob b"
297316
" WHERE filename.fnid=mlink.fnid"
298317
" AND event.objid=mlink.mid"
@@ -305,11 +324,20 @@
305324
/* TODO: add a "state" flag for the file in each checkin,
306325
e.g. "modified", "new", "deleted".
307326
*/
308327
checkin_arr = cson_new_array();
309328
cson_object_set(pay, "checkins", cson_array_value(checkin_arr));
310
- json_stmt_to_array_of_obj( &q, checkin_arr );
329
+ while( (SQLITE_ROW==db_step(&q) ) ){
330
+ cson_object * row = cson_value_get_object(cson_sqlite3_row_to_object(q.pStmt));
331
+ char const isNew = cson_value_get_bool(cson_object_get(row,"isNew"));
332
+ char const isDel = cson_value_get_bool(cson_object_get(row,"isDel"));
333
+ cson_object_set(row, "isNew", NULL);
334
+ cson_object_set(row, "isDel", NULL);
335
+ cson_object_set(row, "status",
336
+ json_new_string(json_artifact_status_to_string(isNew, isDel)));
337
+ cson_array_append( checkin_arr, cson_object_value(row) );
338
+ }
311339
db_finalize(&q);
312340
return cson_object_value(pay);
313341
}
314342
315343
/*
316344
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -248,15 +248,30 @@
248 contentFormat = json_artifact_include_content_flag() ? -1 : 0;
249 }
250 return json_get_wiki_page_by_rid(rid, contentFormat);
251 }
252 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
254 cson_value * json_artifact_file(int rid){
255 cson_object * pay = NULL;
256 const char *zMime;
257 Blob content = empty_blob;
258 Stmt q = empty_Stmt;
259 cson_array * checkin_arr = NULL;
260
261 if( ! g.perm.Read ){
262 json_set_err(FSL_JSON_E_DENIED,
@@ -264,35 +279,39 @@
264 return NULL;
265 }
266
267 pay = cson_new_object();
268
269 content_get(rid, &content);
270 cson_object_set(pay, "contentLength",
271 json_new_int( blob_size(&content) )
272 /* achtung: overflow potential on 32-bit builds! */);
273 zMime = mimetype_from_content(&content);
274
275 cson_object_set(pay, "contentType",
276 json_new_string(zMime ? zMime : "text/plain"));
277 if( json_artifact_include_content_flag() && !zMime ){
278 cson_object_set(pay, "content",
279 cson_value_new_string(blob_str(&content),
280 (unsigned int)blob_size(&content)));
 
 
281 }
282 blob_reset(&content);
283
284 db_prepare(&q,
285 "SELECT filename.name AS name, "
286 " cast(strftime('%%s',event.mtime) as int) AS timestamp,"
287 " coalesce(event.ecomment,event.comment) as comment,"
288 " coalesce(event.euser,event.user) as user,"
289 " b.uuid as uuid, "
 
 
 
290 #if 0
291 " mlink.mperm as mperm,"
292 #endif
293 " coalesce((SELECT value FROM tagxref"
294 " WHERE tagid=%d AND tagtype>0 AND "
295 " rid=mlink.mid),'trunk') as branch"
296 " FROM mlink, filename, event, blob a, blob b"
297 " WHERE filename.fnid=mlink.fnid"
298 " AND event.objid=mlink.mid"
@@ -305,11 +324,20 @@
305 /* TODO: add a "state" flag for the file in each checkin,
306 e.g. "modified", "new", "deleted".
307 */
308 checkin_arr = cson_new_array();
309 cson_object_set(pay, "checkins", cson_array_value(checkin_arr));
310 json_stmt_to_array_of_obj( &q, checkin_arr );
 
 
 
 
 
 
 
 
 
311 db_finalize(&q);
312 return cson_object_value(pay);
313 }
314
315 /*
316
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -248,15 +248,30 @@
248 contentFormat = json_artifact_include_content_flag() ? -1 : 0;
249 }
250 return json_get_wiki_page_by_rid(rid, contentFormat);
251 }
252 }
253
254 /*
255 ** Internal helper for routines which add a "status" flag to file
256 ** artifact data. isNew and isDel should be the "is this object new?"
257 ** and "is this object removed?" flags of the underlying query. This
258 ** function returns a static string from the set (added, removed,
259 ** modified), depending on the combination of the two args.
260 **
261 ** Reminder to self: (mlink.pid==0) AS isNew, (mlink.fid==0) AS isDel
262 */
263 char const * json_artifact_status_to_string( char isNew, char isDel ){
264 return isNew
265 ? "added"
266 : (isDel
267 ? "removed"
268 : "modified");
269 }
270
271 cson_value * json_artifact_file(int rid){
272 cson_object * pay = NULL;
 
 
273 Stmt q = empty_Stmt;
274 cson_array * checkin_arr = NULL;
275
276 if( ! g.perm.Read ){
277 json_set_err(FSL_JSON_E_DENIED,
@@ -264,35 +279,39 @@
279 return NULL;
280 }
281
282 pay = cson_new_object();
283
284 if( json_artifact_include_content_flag() ){
285 Blob content = empty_blob;
286 const char *zMime;
287 content_get(rid, &content);
288 zMime = mimetype_from_content(&content);
289 cson_object_set(pay, "contentType",
290 json_new_string(zMime ? zMime : "text/plain"));
291 cson_object_set(pay, "size", json_new_int( blob_size(&content)) );
292 if(!zMime){
293 cson_object_set(pay, "content",
294 cson_value_new_string(blob_str(&content),
295 (unsigned int)blob_size(&content)));
296 }
297 blob_reset(&content);
298 }
 
299
300 db_prepare(&q,
301 "SELECT filename.name AS name, "
302 " (mlink.pid==0) AS isNew,"
303 " (mlink.fid==0) AS isDel,"
304 " cast(strftime('%%s',event.mtime) as int) AS timestamp,"
305 " coalesce(event.ecomment,event.comment) as comment,"
306 " coalesce(event.euser,event.user) as user,"
307 " a.size AS size,"
308 " b.uuid as uuid, "
309 #if 0
310 " mlink.mperm as mperm,"
311 #endif
312 " coalesce((SELECT value FROM tagxref"
313 " WHERE tagid=%d AND tagtype>0 AND "
314 " rid=mlink.mid),'trunk') as branch"
315 " FROM mlink, filename, event, blob a, blob b"
316 " WHERE filename.fnid=mlink.fnid"
317 " AND event.objid=mlink.mid"
@@ -305,11 +324,20 @@
324 /* TODO: add a "state" flag for the file in each checkin,
325 e.g. "modified", "new", "deleted".
326 */
327 checkin_arr = cson_new_array();
328 cson_object_set(pay, "checkins", cson_array_value(checkin_arr));
329 while( (SQLITE_ROW==db_step(&q) ) ){
330 cson_object * row = cson_value_get_object(cson_sqlite3_row_to_object(q.pStmt));
331 char const isNew = cson_value_get_bool(cson_object_get(row,"isNew"));
332 char const isDel = cson_value_get_bool(cson_object_get(row,"isDel"));
333 cson_object_set(row, "isNew", NULL);
334 cson_object_set(row, "isDel", NULL);
335 cson_object_set(row, "status",
336 json_new_string(json_artifact_status_to_string(isNew, isDel)));
337 cson_array_append( checkin_arr, cson_object_value(row) );
338 }
339 db_finalize(&q);
340 return cson_object_value(pay);
341 }
342
343 /*
344
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -71,12 +71,14 @@
7171
/*3*/ " cast(strftime('%%s',event.mtime) AS INTEGER),"
7272
/*4*/ " coalesce(event.euser, event.user),"
7373
/*5*/ " coalesce(event.ecomment, event.comment),"
7474
/*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
7575
/*7*/ " event.bgcolor,"
76
-/*8*/ " b.size"
77
- " FROM mlink, blob b, event, blob ci, filename"
76
+/*8*/ " b.size,"
77
+/*9*/ " (mlink.pid==0) AS isNew,"
78
+/*10*/ " (mlink.fid==0) AS isDel"
79
+ " FROM mlink, blob b, event, blob ci, filename"
7880
" WHERE filename.name=%Q %s"
7981
" AND mlink.fnid=filename.fnid"
8082
" AND b.rid=mlink.fid"
8183
" AND event.objid=mlink.mid"
8284
" AND event.objid=ci.rid",
@@ -117,19 +119,23 @@
117119
}
118120
checkins = cson_new_array();
119121
cson_object_set(pay, "checkins", cson_array_value(checkins));
120122
while( db_step(&q)==SQLITE_ROW ){
121123
cson_object * row = cson_new_object();
124
+ int const isNew = db_column_int(&q,9);
125
+ int const isDel = db_column_int(&q,10);
122126
cson_array_append( checkins, cson_object_value(row) );
123127
cson_object_set(row, "checkin", json_new_string( db_column_text(&q,1) ));
124128
cson_object_set(row, "uuid", json_new_string( db_column_text(&q,2) ));
125129
/*cson_object_set(row, "parentArtifact", json_new_string( db_column_text(&q,6) ));*/
126130
cson_object_set(row, "timestamp", json_new_int( db_column_int(&q,3) ));
127131
cson_object_set(row, "user", json_new_string( db_column_text(&q,4) ));
128132
cson_object_set(row, "comment", json_new_string( db_column_text(&q,5) ));
129133
/*cson_object_set(row, "bgColor", json_new_string( db_column_text(&q,7) ));*/
130134
cson_object_set(row, "size", cson_value_new_integer( (cson_int_t)db_column_int64(&q,8) ));
135
+ cson_object_set(row, "status",
136
+ json_new_string(json_artifact_status_to_string(isNew,isDel)));
131137
if( (0 < limit) && (++currentRow >= limit) ){
132138
break;
133139
}
134140
}
135141
db_finalize(&q);
136142
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -71,12 +71,14 @@
71 /*3*/ " cast(strftime('%%s',event.mtime) AS INTEGER),"
72 /*4*/ " coalesce(event.euser, event.user),"
73 /*5*/ " coalesce(event.ecomment, event.comment),"
74 /*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
75 /*7*/ " event.bgcolor,"
76 /*8*/ " b.size"
77 " FROM mlink, blob b, event, blob ci, filename"
 
 
78 " WHERE filename.name=%Q %s"
79 " AND mlink.fnid=filename.fnid"
80 " AND b.rid=mlink.fid"
81 " AND event.objid=mlink.mid"
82 " AND event.objid=ci.rid",
@@ -117,19 +119,23 @@
117 }
118 checkins = cson_new_array();
119 cson_object_set(pay, "checkins", cson_array_value(checkins));
120 while( db_step(&q)==SQLITE_ROW ){
121 cson_object * row = cson_new_object();
 
 
122 cson_array_append( checkins, cson_object_value(row) );
123 cson_object_set(row, "checkin", json_new_string( db_column_text(&q,1) ));
124 cson_object_set(row, "uuid", json_new_string( db_column_text(&q,2) ));
125 /*cson_object_set(row, "parentArtifact", json_new_string( db_column_text(&q,6) ));*/
126 cson_object_set(row, "timestamp", json_new_int( db_column_int(&q,3) ));
127 cson_object_set(row, "user", json_new_string( db_column_text(&q,4) ));
128 cson_object_set(row, "comment", json_new_string( db_column_text(&q,5) ));
129 /*cson_object_set(row, "bgColor", json_new_string( db_column_text(&q,7) ));*/
130 cson_object_set(row, "size", cson_value_new_integer( (cson_int_t)db_column_int64(&q,8) ));
 
 
131 if( (0 < limit) && (++currentRow >= limit) ){
132 break;
133 }
134 }
135 db_finalize(&q);
136
--- src/json_finfo.c
+++ src/json_finfo.c
@@ -71,12 +71,14 @@
71 /*3*/ " cast(strftime('%%s',event.mtime) AS INTEGER),"
72 /*4*/ " coalesce(event.euser, event.user),"
73 /*5*/ " coalesce(event.ecomment, event.comment),"
74 /*6*/ " (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file uuid */
75 /*7*/ " event.bgcolor,"
76 /*8*/ " b.size,"
77 /*9*/ " (mlink.pid==0) AS isNew,"
78 /*10*/ " (mlink.fid==0) AS isDel"
79 " FROM mlink, blob b, event, blob ci, filename"
80 " WHERE filename.name=%Q %s"
81 " AND mlink.fnid=filename.fnid"
82 " AND b.rid=mlink.fid"
83 " AND event.objid=mlink.mid"
84 " AND event.objid=ci.rid",
@@ -117,19 +119,23 @@
119 }
120 checkins = cson_new_array();
121 cson_object_set(pay, "checkins", cson_array_value(checkins));
122 while( db_step(&q)==SQLITE_ROW ){
123 cson_object * row = cson_new_object();
124 int const isNew = db_column_int(&q,9);
125 int const isDel = db_column_int(&q,10);
126 cson_array_append( checkins, cson_object_value(row) );
127 cson_object_set(row, "checkin", json_new_string( db_column_text(&q,1) ));
128 cson_object_set(row, "uuid", json_new_string( db_column_text(&q,2) ));
129 /*cson_object_set(row, "parentArtifact", json_new_string( db_column_text(&q,6) ));*/
130 cson_object_set(row, "timestamp", json_new_int( db_column_int(&q,3) ));
131 cson_object_set(row, "user", json_new_string( db_column_text(&q,4) ));
132 cson_object_set(row, "comment", json_new_string( db_column_text(&q,5) ));
133 /*cson_object_set(row, "bgColor", json_new_string( db_column_text(&q,7) ));*/
134 cson_object_set(row, "size", cson_value_new_integer( (cson_int_t)db_column_int64(&q,8) ));
135 cson_object_set(row, "status",
136 json_new_string(json_artifact_status_to_string(isNew,isDel)));
137 if( (0 < limit) && (++currentRow >= limit) ){
138 break;
139 }
140 }
141 db_finalize(&q);
142
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -329,15 +329,11 @@
329329
cson_object_set(row, "uuid", json_new_string(db_column_text(&q,3)));
330330
if(!isNew){
331331
cson_object_set(row, "parent", json_new_string(db_column_text(&q,4)));
332332
}
333333
cson_object_set(row, "state",
334
- json_new_string(isNew
335
- ? "added"
336
- : (isDel
337
- ? "removed"
338
- : "modified")));
334
+ json_new_string(json_artifact_status_to_string(isNew,isDel)));
339335
zDownload = mprintf("/raw/%s?name=%s",
340336
/* reminder: g.zBaseURL is of course not set for CLI mode. */
341337
db_column_text(&q,2),
342338
db_column_text(&q,3));
343339
cson_object_set(row, "downloadPath", json_new_string(zDownload));
344340
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -329,15 +329,11 @@
329 cson_object_set(row, "uuid", json_new_string(db_column_text(&q,3)));
330 if(!isNew){
331 cson_object_set(row, "parent", json_new_string(db_column_text(&q,4)));
332 }
333 cson_object_set(row, "state",
334 json_new_string(isNew
335 ? "added"
336 : (isDel
337 ? "removed"
338 : "modified")));
339 zDownload = mprintf("/raw/%s?name=%s",
340 /* reminder: g.zBaseURL is of course not set for CLI mode. */
341 db_column_text(&q,2),
342 db_column_text(&q,3));
343 cson_object_set(row, "downloadPath", json_new_string(zDownload));
344
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -329,15 +329,11 @@
329 cson_object_set(row, "uuid", json_new_string(db_column_text(&q,3)));
330 if(!isNew){
331 cson_object_set(row, "parent", json_new_string(db_column_text(&q,4)));
332 }
333 cson_object_set(row, "state",
334 json_new_string(json_artifact_status_to_string(isNew,isDel)));
 
 
 
 
335 zDownload = mprintf("/raw/%s?name=%s",
336 /* reminder: g.zBaseURL is of course not set for CLI mode. */
337 db_column_text(&q,2),
338 db_column_text(&q,3));
339 cson_object_set(row, "downloadPath", json_new_string(zDownload));
340

Keyboard Shortcuts

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