154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
}
}
/*
** Load the record ID rid and up to N-1 closest ancestors into
** the "ok" table.
*/
void compute_ancestors(int rid, int N){
Bag seen;
PQueue queue;
Stmt ins;
Stmt q;
bag_init(&seen);
pqueue_init(&queue);
bag_insert(&seen, rid);
pqueue_insert(&queue, rid, 0.0, 0);
db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)");
db_prepare(&q,
"SELECT a.pid, b.mtime FROM plink a LEFT JOIN plink b ON b.cid=a.pid"
" WHERE a.cid=:rid"
);
while( (N--)>0 && (rid = pqueue_extract(&queue, 0))!=0 ){
db_bind_int(&ins, ":rid", rid);
db_step(&ins);
db_reset(&ins);
db_bind_int(&q, ":rid", rid);
while( db_step(&q)==SQLITE_ROW ){
|
|
|
>
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
}
}
/*
** Load the record ID rid and up to N-1 closest ancestors into
** the "ok" table.
*/
void compute_ancestors(int rid, int N, int directOnly){
Bag seen;
PQueue queue;
Stmt ins;
Stmt q;
bag_init(&seen);
pqueue_init(&queue);
bag_insert(&seen, rid);
pqueue_insert(&queue, rid, 0.0, 0);
db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)");
db_prepare(&q,
"SELECT a.pid, b.mtime FROM plink a LEFT JOIN plink b ON b.cid=a.pid"
" WHERE a.cid=:rid %s",
directOnly ? " AND a.isprim" : ""
);
while( (N--)>0 && (rid = pqueue_extract(&queue, 0))!=0 ){
db_bind_int(&ins, ":rid", rid);
db_step(&ins);
db_reset(&ins);
db_bind_int(&q, ":rid", rid);
while( db_step(&q)==SQLITE_ROW ){
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
** direct ancestor as the largest generation number.
*/
void compute_direct_ancestors(int rid, int N){
Stmt ins;
Stmt q;
int gen = 0;
db_multi_exec(
"CREATE TEMP TABLE ancestor(rid INTEGER, generation INTEGER PRIMARY KEY);"
"INSERT INTO ancestor VALUES(%d, 0);", rid
);
db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)");
db_prepare(&q,
"SELECT pid FROM plink"
" WHERE cid=:rid AND isprim"
);
|
>
|
>
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
** direct ancestor as the largest generation number.
*/
void compute_direct_ancestors(int rid, int N){
Stmt ins;
Stmt q;
int gen = 0;
db_multi_exec(
"CREATE TEMP TABLE IF NOT EXISTS ancestor(rid INTEGER,"
" generation INTEGER PRIMARY KEY);"
"DELETE FROM ancestor;"
"INSERT INTO ancestor VALUES(%d, 0);", rid
);
db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)");
db_prepare(&q,
"SELECT pid FROM plink"
" WHERE cid=:rid AND isprim"
);
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
db_bind_int(&ins, ":gen", gen);
db_step(&ins);
db_reset(&ins);
}
db_finalize(&ins);
db_finalize(&q);
}
/*
** Load the record ID rid and up to N-1 closest descendants into
** the "ok" table.
*/
void compute_descendants(int rid, int N){
Bag seen;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
db_bind_int(&ins, ":gen", gen);
db_step(&ins);
db_reset(&ins);
}
db_finalize(&ins);
db_finalize(&q);
}
/*
** Compute the "mtime" of the file given whose blob.rid is "fid" that
** is part of check-in "vid". The mtime will be the mtime on vid or
** some ancestor of vid where fid first appears.
*/
int mtime_of_manifest_file(
int vid, /* The check-in that contains fid */
int fid, /* The id of the file whose check-in time is sought */
i64 *pMTime /* Write result here */
){
static int prevVid = -1;
static Stmt q;
if( prevVid!=vid ){
prevVid = vid;
db_multi_exec("DROP TABLE IF EXISTS temp.ok;"
"CREATE TEMP TABLE ok(x INTEGER PRIMARY KEY);");
compute_ancestors(vid, 100000000, 1);
}
db_static_prepare(&q,
"SELECT (max(event.mtime)-2440587.5)*86400 FROM mlink, event"
" WHERE mlink.mid=event.objid"
" AND +mlink.mid IN ok"
" AND mlink.fid=:fid");
db_bind_int(&q, ":fid", fid);
if( db_step(&q)!=SQLITE_ROW ){
db_reset(&q);
return 1;
}
*pMTime = db_column_int64(&q, 0);
db_reset(&q);
return 0;
}
/*
** Load the record ID rid and up to N-1 closest descendants into
** the "ok" table.
*/
void compute_descendants(int rid, int N){
Bag seen;
|