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.

stephan 2012-02-29 21:39 trunk
Commit 0c9c99b83f936b44fd6c5d0ee5a308b48097e99f
1 file changed +48 -13
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -48,31 +48,49 @@
4848
payload.artifact property of /json/artifact responses.
4949
*/
5050
artifact_f func;
5151
} ArtifactDispatchEntry;
5252
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
+}
5377
5478
/*
5579
** Generates an artifact Object for the given rid,
5680
** which must refer to a Checkin.
5781
**
5882
** Returned value is NULL or an Object owned by the caller.
5983
*/
6084
cson_value * json_artifact_for_ci( int rid, char showFiles ){
61
- char * zParent = NULL;
6285
cson_value * v = NULL;
6386
Stmt q;
6487
static cson_value * eventTypeLabel = NULL;
6588
if(!eventTypeLabel){
6689
eventTypeLabel = json_new_string("checkin");
6790
json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel);
6891
}
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
- );
7492
7593
db_prepare(&q,
7694
"SELECT uuid, "
7795
" cast(strftime('%%s',mtime) as int), "
7896
" user, "
@@ -88,10 +106,14 @@
88106
cson_value * tmpV = NULL;
89107
const char *zUuid = db_column_text(&q, 0);
90108
const char *zUser;
91109
const char *zComment;
92110
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
93115
int mtime, omtime;
94116
v = cson_value_new_object();
95117
o = cson_value_get_object(v);
96118
#define SET(K,V) cson_object_set(o,(K), (V))
97119
SET("type", eventTypeLabel );
@@ -130,30 +152,43 @@
130152
omtime = db_column_int(&q,4);
131153
if(omtime && (omtime!=mtime)){
132154
SET("originTime",json_new_int(omtime));
133155
}
134156
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);
137174
}
138175
139176
tmpV = json_tags_for_checkin_rid(rid,0);
140177
if(tmpV){
141178
SET("tags",tmpV);
142179
}
143180
144181
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);
148185
}
149186
}
150187
151
-
152188
#undef SET
153189
}
154
- free(zParent);
155190
db_finalize(&q);
156191
return v;
157192
}
158193
159194
/*
160195
--- 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

Keyboard Shortcuts

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