269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
}
/* Values for the debug= query parameter to finfo */
#define FINFO_DEBUG_MLINK 0x01
/*
** WEBPAGE: finfo
** URL: /finfo?name=FILENAME
**
** Show the change history for a single file.
**
** Additional query parameters:
**
** a=DATETIME Only show changes after DATETIME
** b=DATETIME Only show changes before DATETIME
** m=HASH Mark this particular file version
** n=NUM Show the first NUM changes only
** name=FILENAME (Required) name of file whose history to show
** brbg Background color by branch name
** ubg Background color by user name
** from=HASH Ancestors of a particular check-in
** to=HASH If both from= and to= are supplied, only show those
** changes on the direct path between them.
** showid Show RID values for debugging
**
** DATETIME may be in any of usual formats, including "now",
** "YYYY-MM-DDTHH:MM:SS.SSS", "YYYYMMDDHHMM", and others.
*/
void finfo_page(void){
Stmt q;
const char *zFilename = PD("name","");
char zPrevDate[20];
const char *zA;
const char *zB;
int n;
int ridFrom;
int ridTo = 0;
int fnid;
Blob title;
Blob sql;
HQuery url;
GraphContext *pGraph;
int brBg = P("brbg")!=0;
int uBg = P("ubg")!=0;
int fDebug = atoi(PD("debug","0"));
int fShowId = P("showid")!=0;
Stmt qparent;
int iTableId = timeline_tableid();
int tmFlags = 0; /* Viewing mode */
const char *zStyle; /* Viewing mode name */
const char *zMark; /* Mark this version of the file */
int selRid = 0; /* RID of the marked file version */
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
if( fnid==0 ){
style_header("No such file");
}else{
style_header("History for %s", zFilename);
}
login_anonymous_available();
tmFlags = timeline_ss_submenu();
if( tmFlags & TIMELINE_COLUMNAR ){
zStyle = "Columnar";
}else if( tmFlags & TIMELINE_COMPACT ){
zStyle = "Compact";
|
>
|
>
|
>
>
>
>
>
>
>
>
>
|
|
>
|
>
>
>
>
>
>
>
>
|
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
}
/* Values for the debug= query parameter to finfo */
#define FINFO_DEBUG_MLINK 0x01
/*
** WEBPAGE: finfo
** Usage:
** * /finfo?name=FILENAME
** * /finfo?name=FILENAME&ci=HASH
**
** Show the change history for a single file. The name=FILENAME query
** parameter gives the filename and is a required parameter. If the
** ci=HASH parameter is also supplied, then the FILENAME,HASH combination
** identifies a particular version of a file, and in that case all changes
** to that one file version are tracked across both edits and renames.
** If only the name=FILENAME parameter is supplied (if ci=HASH is omitted)
** then the graph shows all changes to any file while it happened
** to be called FILENAME and changes are not tracked across renames.
**
** Additional query parameters:
**
** a=DATETIME Only show changes after DATETIME
** b=DATETIME Only show changes before DATETIME
** ci=HASH identify a particular version of a file and then
** track changes to that file across renames
** m=HASH Mark this particular file version.
** n=NUM Show the first NUM changes only
** name=FILENAME (Required) name of file whose history to show
** brbg Background color by branch name
** ubg Background color by user name
** from=HASH Ancestors only (not descendents) of the version of
** the file in this particular check-in.
** to=HASH If both from= and to= are supplied, only show those
** changes on the direct path between the two given
** checkins.
** showid Show RID values for debugging
** showsql Show the SQL query used to gather the data for
** the graph
**
** DATETIME may be in any of usual formats, including "now",
** "YYYY-MM-DDTHH:MM:SS.SSS", "YYYYMMDDHHMM", and others.
*/
void finfo_page(void){
Stmt q;
const char *zFilename = PD("name","");
char zPrevDate[20];
const char *zA;
const char *zB;
int n;
int ridFrom;
int ridTo = 0;
int ridCi = 0;
const char *zCI = P("ci");
int fnid;
Blob title;
Blob sql;
HQuery url;
GraphContext *pGraph;
int brBg = P("brbg")!=0;
int uBg = P("ubg")!=0;
int fDebug = atoi(PD("debug","0"));
int fShowId = P("showid")!=0;
Stmt qparent;
int iTableId = timeline_tableid();
int tmFlags = 0; /* Viewing mode */
const char *zStyle; /* Viewing mode name */
const char *zMark; /* Mark this version of the file */
int selRid = 0; /* RID of the marked file version */
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q", zFilename);
ridCi = zCI ? name_to_rid_www("ci") : 0;
if( fnid==0 ){
style_header("No such file");
}else if( ridCi==0 ){
style_header("All files named \"%s\"", zFilename);
}else{
style_header("History of %s of %s",zFilename, zCI);
}
login_anonymous_available();
tmFlags = timeline_ss_submenu();
if( tmFlags & TIMELINE_COLUMNAR ){
zStyle = "Columnar";
}else if( tmFlags & TIMELINE_COMPACT ){
zStyle = "Compact";
|
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
path_shortest_stored_in_ancestor_table(ridFrom,ridTo);
}else{
compute_direct_ancestors(ridFrom);
}
}
url_add_parameter(&url, "name", zFilename);
blob_zero(&sql);
blob_append_sql(&sql,
"SELECT"
" datetime(min(event.mtime),toLocal())," /* Date of change */
" coalesce(event.ecomment, event.comment)," /* Check-in comment */
" coalesce(event.euser, event.user)," /* User who made chng */
" mlink.pid," /* Parent file rid */
" mlink.fid," /* File rid */
" (SELECT uuid FROM blob WHERE rid=mlink.pid)," /* Parent file hash */
" blob.uuid," /* Current file hash */
" (SELECT uuid FROM blob WHERE rid=mlink.mid)," /* Check-in hash */
" event.bgcolor," /* Background color */
" (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
" AND tagxref.rid=mlink.mid)," /* Branchname */
" mlink.mid," /* check-in ID */
" mlink.pfnid," /* Previous filename */
" blob.size" /* File size */
" FROM mlink, event, blob"
" WHERE mlink.fnid=%d"
" AND event.objid=mlink.mid"
" AND mlink.fid=blob.rid",
TAG_BRANCH, fnid
);
if( (zA = P("a"))!=0 ){
blob_append_sql(&sql, " AND event.mtime>=%.16g",
symbolic_name_to_mtime(zA,0));
url_add_parameter(&url, "a", zA);
}
if( (zB = P("b"))!=0 ){
blob_append_sql(&sql, " AND event.mtime<=%.16g",
symbolic_name_to_mtime(zB,0));
url_add_parameter(&url, "b", zB);
}
if( ridFrom ){
blob_append_sql(&sql,
" AND mlink.mid IN (SELECT rid FROM ancestor)"
" GROUP BY mlink.fid"
);
}else{
/* We only want each version of a file to appear on the graph once,
** at its earliest appearance. All the other times that it gets merged
** into this or that branch can be ignored. An exception is for when
** files are deleted (when they have mlink.fid==0). If the same file
** is deleted in multiple places, we want to show each deletion, so
** use a "fake fid" which is derived from the parent-fid for grouping.
** The same fake-fid must be used on the graph.
*/
blob_append_sql(&sql,
" GROUP BY"
" CASE WHEN mlink.fid>0 THEN mlink.fid ELSE mlink.pid+1000000000 END"
);
}
blob_append_sql(&sql, " ORDER BY event.mtime DESC /*sort*/");
if( (n = atoi(PD("n","0")))>0 ){
blob_append_sql(&sql, " LIMIT %d", n);
url_add_parameter(&url, "n", P("n"));
}
db_prepare(&q, "%s", blob_sql_text(&sql));
if( P("showsql")!=0 ){
@ <p>SQL: %h(blob_str(&sql))</p>
}
zMark = P("m");
if( zMark ){
selRid = symbolic_name_to_rid(zMark, "*");
}
blob_reset(&sql);
blob_zero(&title);
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
path_shortest_stored_in_ancestor_table(ridFrom,ridTo);
}else{
compute_direct_ancestors(ridFrom);
}
}
url_add_parameter(&url, "name", zFilename);
blob_zero(&sql);
if( ridCi ){
/* If we will be tracking changes across renames, some extra temp
** tables (implemented as CTEs) are required */
blob_append_sql(&sql,
/* The fns(fnid) table holds the list of all filename-IDs that
** might possibly exist in the output. This is an optimization
** used to reduce the size and computation efforts for subsequent
** CTEs.
*/
"WITH RECURSIVE fns(fnid) AS (\n"
" SELECT %d\n" /* <---- fnid */
" UNION\n"
" SELECT pfnid FROM mlink, fns\n"
" WHERE mlink.fnid=fns.fnid\n"
" AND pfnid>0\n"
"),\n"
/* The flink(fid,fnid,pfid,pfnid) table indicates that there
** is an edit and/or rename arc connecting two files (fid,fnid)
** and (pfid,pfnid). This is similar to the built-in mlink
** table except that flink() is bidirectional. Also the pfnid
** column is always set even no rename occurs.
*/
"flink(fid,fnid,pfid,pfnid) AS (\n"
" SELECT fid, fnid, pid,\n"
" CASE WHEN pfnid>0 THEN pfnid ELSE fnid END\n"
" FROM mlink\n"
" WHERE NOT isaux AND fid>0 AND pid>0 AND fnid IN fns\n"
" UNION\n"
" SELECT pid,\n"
" CASE WHEN pfnid>0 THEN pfnid ELSE fnid END,\n"
" fid, fnid\n"
" FROM mlink\n"
" WHERE NOT isaux AND pid>0 AND fid>0 AND fnid IN fns\n"
"),\n"
/* The clade(fid,fnid) table is the set of all (fid,fnid) pairs
** that should participate in the output. Clade is computed by
** walking the graph formed by the flink table.
*/
"clade(fid,fnid) AS (\n"
" SELECT blob.rid, %d FROM blob\n" /* %d is fnid */
" WHERE blob.uuid=(SELECT uuid FROM files_of_checkin(%Q)\n"
" WHERE filename=%Q)\n" /* %Q is the filename */
" UNION\n"
" SELECT flink.fid, flink.fnid\n"
" FROM clade, flink\n"
" WHERE clade.fid=flink.pfid AND clade.fnid=flink.pfnid\n"
")\n",
fnid, fnid, zCI, zFilename
);
}else{
/* This is the case for all files with a given name. We will still
** create a "clade(fid,fnid)" table that identifies all participates
** in the output graph, so that subsequent queries can all be the same,
** but in the case the clade table is much simplier, being just a
** single direct query against the mlink table.
*/
blob_append_sql(&sql,
"WITH clade(fid,fnid) AS (\n"
" SELECT DISTINCT fid, %d\n"
" FROM mlink\n"
" WHERE fnid=%d)",
fnid, fnid
);
}
blob_append_sql(&sql,
"SELECT\n"
" datetime(min(event.mtime),toLocal()),\n" /* Date of change */
" coalesce(event.ecomment, event.comment),\n" /* Check-in comment */
" coalesce(event.euser, event.user),\n" /* User who made chng */
" mlink.pid,\n" /* Parent file rid */
" mlink.fid,\n" /* File rid */
" (SELECT uuid FROM blob WHERE rid=mlink.pid),\n" /* Parent file hash */
" blob.uuid,\n" /* Current file hash */
" (SELECT uuid FROM blob WHERE rid=mlink.mid),\n" /* Check-in hash */
" event.bgcolor,\n" /* Background color */
" (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
" AND tagxref.rid=mlink.mid),\n" /* Branchname */
" mlink.mid,\n" /* check-in ID */
" mlink.pfnid,\n" /* Previous filename */
" blob.size,\n" /* File size */
" mlink.fnid\n" /* Current filename */
"FROM clade, mlink, event, blob\n"
"WHERE mlink.fnid=clade.fnid AND mlink.fid=clade.fid\n"
" AND event.objid=mlink.mid\n"
" AND blob.rid=clade.fid\n",
TAG_BRANCH
);
if( (zA = P("a"))!=0 ){
blob_append_sql(&sql, " AND event.mtime>=%.16g\n",
symbolic_name_to_mtime(zA,0));
url_add_parameter(&url, "a", zA);
}
if( (zB = P("b"))!=0 ){
blob_append_sql(&sql, " AND event.mtime<=%.16g\n",
symbolic_name_to_mtime(zB,0));
url_add_parameter(&url, "b", zB);
}
if( ridFrom ){
blob_append_sql(&sql,
" AND mlink.mid IN (SELECT rid FROM ancestor)\n"
"GROUP BY mlink.fid\n"
);
}else{
/* We only want each version of a file to appear on the graph once,
** at its earliest appearance. All the other times that it gets merged
** into this or that branch can be ignored. An exception is for when
** files are deleted (when they have mlink.fid==0). If the same file
** is deleted in multiple places, we want to show each deletion, so
** use a "fake fid" which is derived from the parent-fid for grouping.
** The same fake-fid must be used on the graph.
*/
blob_append_sql(&sql,
"GROUP BY"
" CASE WHEN mlink.fid>0 THEN mlink.fid ELSE mlink.pid+1000000000 END\n"
);
}
blob_append_sql(&sql, "ORDER BY event.mtime DESC");
if( (n = atoi(PD("n","0")))>0 ){
blob_append_sql(&sql, " LIMIT %d", n);
url_add_parameter(&url, "n", P("n"));
}
blob_append_sql(&sql, " /*sort*/\n");
db_prepare(&q, "%s", blob_sql_text(&sql));
if( P("showsql")!=0 ){
@ <p>SQL: <blockquote><pre>%h(blob_str(&sql))</blockquote></pre>
}
zMark = P("m");
if( zMark ){
selRid = symbolic_name_to_rid(zMark, "*");
}
blob_reset(&sql);
blob_zero(&title);
|
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
fossil_free(zUuid);
if( ridTo ){
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", ridTo);
zLink = href("%R/info/%!S", zUuid);
blob_appendf(&title, " and check-in %z%S</a>", zLink, zUuid);
fossil_free(zUuid);
}
}else{
blob_appendf(&title, "History for ");
hyperlinked_path(zFilename, &title, 0, "tree", "", LINKPATH_FILE);
if( fShowId ) blob_appendf(&title, " (%d)", fnid);
}
if( uBg ){
blob_append(&title, " (color-coded by user)", -1);
|
>
>
>
>
>
>
|
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
fossil_free(zUuid);
if( ridTo ){
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", ridTo);
zLink = href("%R/info/%!S", zUuid);
blob_appendf(&title, " and check-in %z%S</a>", zLink, zUuid);
fossil_free(zUuid);
}
}else if( ridCi ){
blob_appendf(&title, "History of the file that is called ");
hyperlinked_path(zFilename, &title, 0, "tree", "", LINKPATH_FILE);
if( fShowId ) blob_appendf(&title, " (%d)", fnid);
blob_appendf(&title, " at checkin %z%h</a>",
href("%R/info?name=%t",zCI), zCI);
}else{
blob_appendf(&title, "History for ");
hyperlinked_path(zFilename, &title, 0, "tree", "", LINKPATH_FILE);
if( fShowId ) blob_appendf(&title, " (%d)", fnid);
}
if( uBg ){
blob_append(&title, " (color-coded by user)", -1);
|
490
491
492
493
494
495
496
497
498
499
500
501
502
503
|
const char *zUuid = db_column_text(&q, 6);
const char *zCkin = db_column_text(&q,7);
const char *zBgClr = db_column_text(&q, 8);
const char *zBr = db_column_text(&q, 9);
int fmid = db_column_int(&q, 10);
int pfnid = db_column_int(&q, 11);
int szFile = db_column_int(&q, 12);
int gidx;
char zTime[10];
int nParent = 0;
int aParent[GR_MAX_RAIL];
db_bind_int(&qparent, ":fid", frid);
db_bind_int(&qparent, ":mid", fmid);
|
>
|
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
|
const char *zUuid = db_column_text(&q, 6);
const char *zCkin = db_column_text(&q,7);
const char *zBgClr = db_column_text(&q, 8);
const char *zBr = db_column_text(&q, 9);
int fmid = db_column_int(&q, 10);
int pfnid = db_column_int(&q, 11);
int szFile = db_column_int(&q, 12);
int fnid = db_column_int(&q, 13);
int gidx;
char zTime[10];
int nParent = 0;
int aParent[GR_MAX_RAIL];
db_bind_int(&qparent, ":fid", frid);
db_bind_int(&qparent, ":mid", fmid);
|
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
@ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
@ [blame]</a>
@ %z(href("%R/timeline?n=all&uf=%!S",zUuid))[check-ins using]</a>
if( fpid>0 ){
@ %z(href("%R/fdiff?v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
}
if( fileedit_is_editable(zFilename) ){
@ %z(href("%R/fileedit?filename=%T&checkin=%!S",zFilename,zCkin))[edit]</a>
}
@ </span></span>
}
if( fDebug & FINFO_DEBUG_MLINK ){
int ii;
char *zAncLink;
@ <br />fid=%d(frid) pid=%d(fpid) mid=%d(fmid)
if( nParent>0 ){
@ parents=%d(aParent[0])
for(ii=1; ii<nParent; ii++){
@ %d(aParent[ii])
}
}
zAncLink = href("%R/finfo?name=%T&ci=%!S&debug=1",zFilename,zCkin);
@ %z(zAncLink)[ancestry]</a>
}
tag_private_status(frid);
/* End timelineDetail */
if( tmFlags & TIMELINE_COMPACT ){
@ </span></span>
}else{
|
|
>
|
|
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
@ %z(href("%R/blame?filename=%h&checkin=%s",z,zCkin))
@ [blame]</a>
@ %z(href("%R/timeline?n=all&uf=%!S",zUuid))[check-ins using]</a>
if( fpid>0 ){
@ %z(href("%R/fdiff?v1=%!S&v2=%!S",zPUuid,zUuid))[diff]</a>
}
if( fileedit_is_editable(zFilename) ){
@ %z(href("%R/fileedit?filename=%T&checkin=%!S",zFilename,zCkin))\
@ [edit]</a>
}
@ </span></span>
}
if( fDebug & FINFO_DEBUG_MLINK ){
int ii;
char *zAncLink;
@ <br />fid=%d(frid) pid=%d(fpid) mid=%d(fmid)
if( nParent>0 ){
@ parents=%d(aParent[0])
for(ii=1; ii<nParent; ii++){
@ %d(aParent[ii])
}
}
zAncLink = href("%R/finfo?name=%T&from=%!S&debug=1",zFilename,zCkin);
@ %z(zAncLink)[ancestry]</a>
}
tag_private_status(frid);
/* End timelineDetail */
if( tmFlags & TIMELINE_COMPACT ){
@ </span></span>
}else{
|