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
356
357
358
359
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
|
typedef struct FileTreeNode FileTreeNode;
typedef struct FileTree FileTree;
/*
** A single line of the file hierarchy
*/
struct FileTreeNode {
FileTreeNode *pNext; /* Next line in sequence */
FileTreeNode *pPrev; /* Previous line */
FileTreeNode *pParent; /* Directory containing this line */
char *zName; /* Name of this entry. The "tail" */
char *zFullName; /* Full pathname of this entry */
char *zUuid; /* SHA1 hash of this file. May be NULL. */
double mtime; /* Modification time for this entry */
unsigned nFullName; /* Length of zFullName */
unsigned iLevel; /* Levels of parent directories */
u8 isDir; /* True if there are children */
u8 isLast; /* True if this is the last child of its parent */
};
/*
** A complete file hierarchy
*/
struct FileTree {
FileTreeNode *pFirst; /* First line of the list */
FileTreeNode *pLast; /* Last line of the list */
};
/*
** Add one or more new FileTreeNodes to the FileTree object so that the
** leaf object zPathname is at the end of the node list
*/
static void tree_add_node(
FileTree *pTree, /* Tree into which nodes are added */
const char *zPath, /* The full pathname of file to add */
const char *zUuid, /* UUID of the file. Might be NULL. */
double mtime /* Modification time for this entry */
){
int i;
FileTreeNode *pParent;
FileTreeNode *pChild;
pChild = pTree->pLast;
pParent = pChild ? pChild->pParent : 0;
while( pParent!=0 &&
( strncmp(pParent->zFullName, zPath, pParent->nFullName)!=0
|| zPath[pParent->nFullName]!='/' )
){
pChild = pParent;
pParent = pChild->pParent;
}
i = pParent ? pParent->nFullName+1 : 0;
if( pChild ) pChild->isLast = 0;
while( zPath[i] ){
FileTreeNode *pNew;
int iStart = i;
int nByte;
while( zPath[i] && zPath[i]!='/' ){ i++; }
nByte = sizeof(*pNew) + i + 1;
if( zUuid!=0 && zPath[i]==0 ) nByte += UUID_SIZE+1;
pNew = fossil_malloc( nByte );
pNew->zFullName = (char*)&pNew[1];
memcpy(pNew->zFullName, zPath, i);
pNew->zFullName[i] = 0;
pNew->nFullName = i;
if( zUuid!=0 && zPath[i]==0 ){
pNew->zUuid = pNew->zFullName + i + 1;
memcpy(pNew->zUuid, zUuid, UUID_SIZE+1);
}else{
pNew->zUuid = 0;
}
pNew->zName = pNew->zFullName + iStart;
if( pTree->pLast ){
pTree->pLast->pNext = pNew;
}else{
pTree->pFirst = pNew;
}
pNew->pPrev = pTree->pLast;
pNew->pNext = 0;
pNew->pParent = pParent;
pTree->pLast = pNew;
pNew->iLevel = pParent ? pParent->iLevel+1 : 0;
pNew->isDir = zPath[i]=='/';
pNew->isLast = 1;
pNew->mtime = mtime;
while( zPath[i]=='/' ){ i++; }
pParent = pNew;
}
while( pParent && pParent->pParent ){
if( pParent->pParent->mtime < pParent->mtime ){
pParent->pParent->mtime = pParent->mtime;
}
pParent = pParent->pParent;
}
}
/*
** WEBPAGE: tree
**
** Query parameters:
**
** name=PATH Directory to display. Optional
** ci=LABEL Show only files in this check-in. Optional.
** re=REGEXP Show only files matching REGEXP. Optional.
** expand Begin with the tree fully expanded.
** nofiles Show directories (folders) only. Omit files.
*/
void page_tree(void){
char *zD = fossil_strdup(P("name"));
int nD = zD ? strlen(zD)+1 : 0;
const char *zCI = P("ci");
int rid = 0;
char *zUuid = 0;
|
|
<
|
>
>
>
<
<
>
|
>
>
>
>
>
>
>
>
|
<
>
>
>
|
<
|
<
<
>
<
<
|
<
>
>
>
>
|
>
|
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
356
357
358
359
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
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
521
522
523
|
typedef struct FileTreeNode FileTreeNode;
typedef struct FileTree FileTree;
/*
** A single line of the file hierarchy
*/
struct FileTreeNode {
FileTreeNode *pNext; /* Next entry in an ordered list of them all */
FileTreeNode *pParent; /* Directory containing this entry */
FileTreeNode *pSibling; /* Next element in the same subdirectory */
FileTreeNode *pChild; /* List of child nodes */
FileTreeNode *pLastChild; /* Last child on the pChild list */
char *zName; /* Name of this entry. The "tail" */
char *zFullName; /* Full pathname of this entry */
char *zUuid; /* SHA1 hash of this file. May be NULL. */
double mtime; /* Modification time for this entry */
unsigned nFullName; /* Length of zFullName */
unsigned iLevel; /* Levels of parent directories */
};
/*
** A complete file hierarchy
*/
struct FileTree {
FileTreeNode *pFirst; /* First line of the list */
FileTreeNode *pLast; /* Last line of the list */
FileTreeNode *pLastTop; /* Last top-level node */
};
/*
** Add one or more new FileTreeNodes to the FileTree object so that the
** leaf object zPathname is at the end of the node list.
**
** The caller invokes this routine once for each leaf node (each file
** as opposed to each directory). This routine fills in any missing
** intermediate nodes automatically.
**
** When constructing a list of FileTreeNodes, all entries that have
** a common directory prefix must be added consecutively in order for
** the tree to be constructed properly.
*/
static void tree_add_node(
FileTree *pTree, /* Tree into which nodes are added */
const char *zPath, /* The full pathname of file to add */
const char *zUuid, /* UUID of the file. Might be NULL. */
double mtime /* Modification time for this entry */
){
int i;
FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
/* Make pParent point to the most recent ancestor of zPath, or
** NULL if there are no prior entires that are a container for zPath.
*/
pParent = pTree->pLast;
while( pParent!=0 &&
( strncmp(pParent->zFullName, zPath, pParent->nFullName)!=0
|| zPath[pParent->nFullName]!='/' )
){
pParent = pParent->pParent;
}
i = pParent ? pParent->nFullName+1 : 0;
while( zPath[i] ){
FileTreeNode *pNew;
int iStart = i;
int nByte;
while( zPath[i] && zPath[i]!='/' ){ i++; }
nByte = sizeof(*pNew) + i + 1;
if( zUuid!=0 && zPath[i]==0 ) nByte += UUID_SIZE+1;
pNew = fossil_malloc( nByte );
memset(pNew, 0, sizeof(*pNew));
pNew->zFullName = (char*)&pNew[1];
memcpy(pNew->zFullName, zPath, i);
pNew->zFullName[i] = 0;
pNew->nFullName = i;
if( zUuid!=0 && zPath[i]==0 ){
pNew->zUuid = pNew->zFullName + i + 1;
memcpy(pNew->zUuid, zUuid, UUID_SIZE+1);
}
pNew->zName = pNew->zFullName + iStart;
if( pTree->pLast ){
pTree->pLast->pNext = pNew;
}else{
pTree->pFirst = pNew;
}
pTree->pLast = pNew;
pNew->pParent = pParent;
if( pParent ){
if( pParent->pChild ){
pParent->pLastChild->pSibling = pNew;
}else{
pParent->pChild = pNew;
}
pNew->iLevel = pParent->iLevel + 1;
pParent->pLastChild = pNew;
}else{
if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
pTree->pLastTop = pNew;
}
pNew->mtime = mtime;
while( zPath[i]=='/' ){ i++; }
pParent = pNew;
}
while( pParent && pParent->pParent ){
if( pParent->pParent->mtime < pParent->mtime ){
pParent->pParent->mtime = pParent->mtime;
}
pParent = pParent->pParent;
}
}
/* Comparison function for two FileTreeNode objects. Sort first by
** mtime (larger numbers first) and then by zName (smaller names first).
**
** Return negative if pLeft<pRight.
** Return positive if pLeft>pRight.
** Return zero if pLeft==pRight.
*/
static int compareNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
if( pLeft->mtime>pRight->mtime ) return -1;
if( pLeft->mtime<pRight->mtime ) return +1;
return fossil_stricmp(pLeft->zName, pRight->zName);
}
/* Merge together two sorted lists of FileTreeNode objects */
static FileTreeNode *mergeNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
FileTreeNode *pEnd;
FileTreeNode base;
pEnd = &base;
while( pLeft && pRight ){
if( compareNodes(pLeft,pRight)<=0 ){
pEnd = pEnd->pSibling = pLeft;
pLeft = pLeft->pSibling;
}else{
pEnd = pEnd->pSibling = pRight;
pRight = pRight->pSibling;
}
}
if( pLeft ){
pEnd->pSibling = pLeft;
}else{
pEnd->pSibling = pRight;
}
return base.pSibling;
}
/* Sort a list of FileTreeNode objects in mtime order. */
static FileTreeNode *sortNodesByMtime(FileTreeNode *p){
FileTreeNode *a[30];
FileTreeNode *pX;
int i;
memset(a, 0, sizeof(a));
while( p ){
pX = p;
p = pX->pSibling;
pX->pSibling = 0;
for(i=0; i<count(a)-1 && a[i]!=0; i++){
pX = mergeNodes(a[i], pX);
a[i] = 0;
}
a[i] = mergeNodes(a[i], pX);
}
pX = 0;
for(i=0; i<count(a); i++){
pX = mergeNodes(a[i], pX);
}
return pX;
}
/* Sort an entire FileTreeNode tree by mtime
**
** This routine invalidates the following fields:
**
** FileTreeNode.pLastChild
** FileTreeNode.pNext
**
** Use relinkTree to reconnect the pNext pointers.
*/
static FileTreeNode *sortTreeByMtime(FileTreeNode *p){
FileTreeNode *pX;
for(pX=p; pX; pX=pX->pSibling){
if( pX->pChild ) pX->pChild = sortTreeByMtime(pX->pChild);
}
return sortNodesByMtime(p);
}
/* Reconstruct the FileTree by reconnecting the FileTreeNode.pNext
** fields in sequential order.
*/
static void relinkTree(FileTree *pTree, FileTreeNode *pRoot){
while( pRoot ){
if( pTree->pLast ){
pTree->pLast->pNext = pRoot;
}else{
pTree->pFirst = pRoot;
}
pTree->pLast = pRoot;
if( pRoot->pChild ) relinkTree(pTree, pRoot->pChild);
pRoot = pRoot->pSibling;
}
if( pTree->pLast ) pTree->pLast->pNext = 0;
}
/*
** WEBPAGE: tree
**
** Query parameters:
**
** name=PATH Directory to display. Optional
** ci=LABEL Show only files in this check-in. Optional.
** re=REGEXP Show only files matching REGEXP. Optional.
** expand Begin with the tree fully expanded.
** nofiles Show directories (folders) only. Omit files.
** mtime Order directory elements by decreasing mtime
*/
void page_tree(void){
char *zD = fossil_strdup(P("name"));
int nD = zD ? strlen(zD)+1 : 0;
const char *zCI = P("ci");
int rid = 0;
char *zUuid = 0;
|
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
nFile++;
}
db_finalize(&q);
}
if( showDirOnly ){
for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
if( p->isDir && p->nFullName>nD ) nFile++;
}
zObjType = "folders";
style_submenu_element("Files","Files","%s",
url_render(&sURI,"nofiles",0,0,0));
}else{
zObjType = "files";
style_submenu_element("Folders","Folders","%s",
|
|
|
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
nFile++;
}
db_finalize(&q);
}
if( showDirOnly ){
for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
if( p->pChild!=0 && p->nFullName>nD ) nFile++;
}
zObjType = "folders";
style_submenu_element("Files","Files","%s",
url_render(&sURI,"nofiles",0,0,0));
}else{
zObjType = "files";
style_submenu_element("Folders","Folders","%s",
|
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
|
@ <div class="filetreeline">
@ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a>
if( zNow ){
@ <div class="filetreeage">%s(zNow)</div>
}
@ </div>
@ <ul>
for(p=sTree.pFirst, nDir=0; p; p=p->pNext){
const char *zLastClass = p->isLast ? " last" : "";
if( p->isDir ){
const char *zSubdirClass = p->nFullName==nD-1 ? " subdir" : "";
@ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
@ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
if( p->mtime>0.0 ){
char *zAge = human_readable_age(rNow - p->mtime);
@ <div class="filetreeage">%s(zAge)</div>
}
|
>
>
>
>
>
|
|
|
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
@ <div class="filetreeline">
@ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a>
if( zNow ){
@ <div class="filetreeage">%s(zNow)</div>
}
@ </div>
@ <ul>
if( zCI && P("mtime")!=0 ){
p = sortTreeByMtime(sTree.pFirst);
memset(&sTree, 0, sizeof(sTree));
relinkTree(&sTree, p);
}
for(p=sTree.pFirst, nDir=0; p; p=p->pNext){
const char *zLastClass = p->pSibling==0 ? " last" : "";
if( p->pChild ){
const char *zSubdirClass = p->nFullName==nD-1 ? " subdir" : "";
@ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
@ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
if( p->mtime>0.0 ){
char *zAge = human_readable_age(rNow - p->mtime);
@ <div class="filetreeage">%s(zAge)</div>
}
|
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
@ %z(zLink)%h(p->zName)</a>
if( p->mtime>0 ){
char *zAge = human_readable_age(rNow - p->mtime);
@ <div class="filetreeage">%s(zAge)</div>
}
@ </div>
}
if( p->isLast ){
int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
while( nClose-- > 0 ){
@ </ul>
}
}
}
@ </ul>
|
|
|
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
@ %z(zLink)%h(p->zName)</a>
if( p->mtime>0 ){
char *zAge = human_readable_age(rNow - p->mtime);
@ <div class="filetreeage">%s(zAge)</div>
}
@ </div>
}
if( p->pSibling==0 ){
int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
while( nClose-- > 0 ){
@ </ul>
}
}
}
@ </ul>
|