Fossil SCM

Display file sizes in /dir and /tree, as per request in [forum:2a0cd67e77|forum post 2a0cd67e77].

danield 2023-07-21 23:02 trunk
Commit fb0b7fe140318f51b797a2c2b8645e930bf2c83a1dc354dde407b895743e66d7
2 files changed +15 -7 +8 -1
+15 -7
--- src/browse.c
+++ src/browse.c
@@ -442,10 +442,11 @@
442442
FileTreeNode *pLastChild; /* Last child on the pChild list */
443443
char *zName; /* Name of this entry. The "tail" */
444444
char *zFullName; /* Full pathname of this entry */
445445
char *zUuid; /* Artifact hash of this file. May be NULL. */
446446
double mtime; /* Modification time for this entry */
447
+ int iSize; /* Size for this entry */
447448
unsigned nFullName; /* Length of zFullName */
448449
unsigned iLevel; /* Levels of parent directories */
449450
};
450451
451452
/*
@@ -471,15 +472,16 @@
471472
*/
472473
static void tree_add_node(
473474
FileTree *pTree, /* Tree into which nodes are added */
474475
const char *zPath, /* The full pathname of file to add */
475476
const char *zUuid, /* Hash of the file. Might be NULL. */
476
- double mtime /* Modification time for this entry */
477
+ double mtime, /* Modification time for this entry */
478
+ int size /* Size for this entry */
477479
){
478480
int i;
479481
FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
480
-
482
+//fossil_print("<pre>zPath %s zUuid %s mtime %f size %d</pre>\n",zPath,zUuid,mtime,size);
481483
/* Make pParent point to the most recent ancestor of zPath, or
482484
** NULL if there are no prior entires that are a container for zPath.
483485
*/
484486
pParent = pTree->pLast;
485487
while( pParent!=0 &&
@@ -525,10 +527,11 @@
525527
}else{
526528
if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
527529
pTree->pLastTop = pNew;
528530
}
529531
pNew->mtime = mtime;
532
+ pNew->iSize = size;
530533
while( zPath[i]=='/' ){ i++; }
531534
pParent = pNew;
532535
}
533536
while( pParent && pParent->pParent ){
534537
if( pParent->pParent->mtime < pParent->mtime ){
@@ -788,46 +791,49 @@
788791
*/
789792
if( zCI ){
790793
Stmt q;
791794
compute_fileage(rid, 0);
792795
db_prepare(&q,
793
- "SELECT filename.name, blob.uuid, fileage.mtime\n"
796
+ "SELECT filename.name, blob.uuid, blob.size, fileage.mtime\n"
794797
" FROM fileage, filename, blob\n"
795798
" WHERE filename.fnid=fileage.fnid\n"
796799
" AND blob.rid=fileage.fid\n"
797800
" ORDER BY filename.name COLLATE uintnocase;"
798801
);
799802
while( db_step(&q)==SQLITE_ROW ){
800803
const char *zFile = db_column_text(&q,0);
801804
const char *zUuid = db_column_text(&q,1);
802
- double mtime = db_column_double(&q,2);
805
+ int size = db_column_int(&q,2);
806
+ double mtime = db_column_double(&q,3);
803807
if( nD>0 && (fossil_strncmp(zFile, zD, nD-1)!=0 || zFile[nD-1]!='/') ){
804808
continue;
805809
}
806810
if( pRE && re_match(pRE, (const unsigned char*)zFile, -1)==0 ) continue;
807
- tree_add_node(&sTree, zFile, zUuid, mtime);
811
+ tree_add_node(&sTree, zFile, zUuid, mtime, size);
808812
}
809813
db_finalize(&q);
810814
}else{
811815
Stmt q;
812816
db_prepare(&q,
813817
"SELECT\n"
814818
" (SELECT name FROM filename WHERE filename.fnid=mlink.fnid),\n"
815819
" (SELECT uuid FROM blob WHERE blob.rid=mlink.fid),\n"
820
+ " (SELECT size FROM blob WHERE blob.rid=mlink.fid),\n"
816821
" max(event.mtime)\n"
817822
" FROM mlink JOIN event ON event.objid=mlink.mid\n"
818823
" GROUP BY mlink.fnid\n"
819824
" ORDER BY 1 COLLATE uintnocase;");
820825
while( db_step(&q)==SQLITE_ROW ){
821826
const char *zName = db_column_text(&q, 0);
822827
const char *zUuid = db_column_text(&q,1);
823
- double mtime = db_column_double(&q,2);
828
+ int size = db_column_int(&q,2);
829
+ double mtime = db_column_double(&q,3);
824830
if( nD>0 && (fossil_strncmp(zName, zD, nD-1)!=0 || zName[nD-1]!='/') ){
825831
continue;
826832
}
827833
if( pRE && re_match(pRE, (const u8*)zName, -1)==0 ) continue;
828
- tree_add_node(&sTree, zName, zUuid, mtime);
834
+ tree_add_node(&sTree, zName, zUuid, mtime, size);
829835
}
830836
db_finalize(&q);
831837
}
832838
style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
833839
@@ -902,10 +908,11 @@
902908
@ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
903909
@ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
904910
if( p->mtime>0.0 ){
905911
char *zAge = human_readable_age(rNow - p->mtime);
906912
@ <div class="filetreeage">%s(zAge)</div>
913
+ @ <div class="filetreesize"></div>
907914
}
908915
@ </div>
909916
if( startExpanded || (int)(p->nFullName)<=nD ){
910917
@ <ul id="dir%d(nDir)">
911918
}else{
@@ -923,10 +930,11 @@
923930
@ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
924931
@ %z(zLink)%h(p->zName)</a>
925932
if( p->mtime>0 ){
926933
char *zAge = human_readable_age(rNow - p->mtime);
927934
@ <div class="filetreeage">%s(zAge)</div>
935
+ @ <div class="filetreesize">%s(p->iSize ? mprintf("%,d",p->iSize) : "-")</div>
928936
}
929937
@ </div>
930938
}
931939
if( p->pSibling==0 ){
932940
int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
933941
--- src/browse.c
+++ src/browse.c
@@ -442,10 +442,11 @@
442 FileTreeNode *pLastChild; /* Last child on the pChild list */
443 char *zName; /* Name of this entry. The "tail" */
444 char *zFullName; /* Full pathname of this entry */
445 char *zUuid; /* Artifact hash of this file. May be NULL. */
446 double mtime; /* Modification time for this entry */
 
447 unsigned nFullName; /* Length of zFullName */
448 unsigned iLevel; /* Levels of parent directories */
449 };
450
451 /*
@@ -471,15 +472,16 @@
471 */
472 static void tree_add_node(
473 FileTree *pTree, /* Tree into which nodes are added */
474 const char *zPath, /* The full pathname of file to add */
475 const char *zUuid, /* Hash of the file. Might be NULL. */
476 double mtime /* Modification time for this entry */
 
477 ){
478 int i;
479 FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
480
481 /* Make pParent point to the most recent ancestor of zPath, or
482 ** NULL if there are no prior entires that are a container for zPath.
483 */
484 pParent = pTree->pLast;
485 while( pParent!=0 &&
@@ -525,10 +527,11 @@
525 }else{
526 if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
527 pTree->pLastTop = pNew;
528 }
529 pNew->mtime = mtime;
 
530 while( zPath[i]=='/' ){ i++; }
531 pParent = pNew;
532 }
533 while( pParent && pParent->pParent ){
534 if( pParent->pParent->mtime < pParent->mtime ){
@@ -788,46 +791,49 @@
788 */
789 if( zCI ){
790 Stmt q;
791 compute_fileage(rid, 0);
792 db_prepare(&q,
793 "SELECT filename.name, blob.uuid, fileage.mtime\n"
794 " FROM fileage, filename, blob\n"
795 " WHERE filename.fnid=fileage.fnid\n"
796 " AND blob.rid=fileage.fid\n"
797 " ORDER BY filename.name COLLATE uintnocase;"
798 );
799 while( db_step(&q)==SQLITE_ROW ){
800 const char *zFile = db_column_text(&q,0);
801 const char *zUuid = db_column_text(&q,1);
802 double mtime = db_column_double(&q,2);
 
803 if( nD>0 && (fossil_strncmp(zFile, zD, nD-1)!=0 || zFile[nD-1]!='/') ){
804 continue;
805 }
806 if( pRE && re_match(pRE, (const unsigned char*)zFile, -1)==0 ) continue;
807 tree_add_node(&sTree, zFile, zUuid, mtime);
808 }
809 db_finalize(&q);
810 }else{
811 Stmt q;
812 db_prepare(&q,
813 "SELECT\n"
814 " (SELECT name FROM filename WHERE filename.fnid=mlink.fnid),\n"
815 " (SELECT uuid FROM blob WHERE blob.rid=mlink.fid),\n"
 
816 " max(event.mtime)\n"
817 " FROM mlink JOIN event ON event.objid=mlink.mid\n"
818 " GROUP BY mlink.fnid\n"
819 " ORDER BY 1 COLLATE uintnocase;");
820 while( db_step(&q)==SQLITE_ROW ){
821 const char *zName = db_column_text(&q, 0);
822 const char *zUuid = db_column_text(&q,1);
823 double mtime = db_column_double(&q,2);
 
824 if( nD>0 && (fossil_strncmp(zName, zD, nD-1)!=0 || zName[nD-1]!='/') ){
825 continue;
826 }
827 if( pRE && re_match(pRE, (const u8*)zName, -1)==0 ) continue;
828 tree_add_node(&sTree, zName, zUuid, mtime);
829 }
830 db_finalize(&q);
831 }
832 style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
833
@@ -902,10 +908,11 @@
902 @ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
903 @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
904 if( p->mtime>0.0 ){
905 char *zAge = human_readable_age(rNow - p->mtime);
906 @ <div class="filetreeage">%s(zAge)</div>
 
907 }
908 @ </div>
909 if( startExpanded || (int)(p->nFullName)<=nD ){
910 @ <ul id="dir%d(nDir)">
911 }else{
@@ -923,10 +930,11 @@
923 @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
924 @ %z(zLink)%h(p->zName)</a>
925 if( p->mtime>0 ){
926 char *zAge = human_readable_age(rNow - p->mtime);
927 @ <div class="filetreeage">%s(zAge)</div>
 
928 }
929 @ </div>
930 }
931 if( p->pSibling==0 ){
932 int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
933
--- src/browse.c
+++ src/browse.c
@@ -442,10 +442,11 @@
442 FileTreeNode *pLastChild; /* Last child on the pChild list */
443 char *zName; /* Name of this entry. The "tail" */
444 char *zFullName; /* Full pathname of this entry */
445 char *zUuid; /* Artifact hash of this file. May be NULL. */
446 double mtime; /* Modification time for this entry */
447 int iSize; /* Size for this entry */
448 unsigned nFullName; /* Length of zFullName */
449 unsigned iLevel; /* Levels of parent directories */
450 };
451
452 /*
@@ -471,15 +472,16 @@
472 */
473 static void tree_add_node(
474 FileTree *pTree, /* Tree into which nodes are added */
475 const char *zPath, /* The full pathname of file to add */
476 const char *zUuid, /* Hash of the file. Might be NULL. */
477 double mtime, /* Modification time for this entry */
478 int size /* Size for this entry */
479 ){
480 int i;
481 FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
482 //fossil_print("<pre>zPath %s zUuid %s mtime %f size %d</pre>\n",zPath,zUuid,mtime,size);
483 /* Make pParent point to the most recent ancestor of zPath, or
484 ** NULL if there are no prior entires that are a container for zPath.
485 */
486 pParent = pTree->pLast;
487 while( pParent!=0 &&
@@ -525,10 +527,11 @@
527 }else{
528 if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
529 pTree->pLastTop = pNew;
530 }
531 pNew->mtime = mtime;
532 pNew->iSize = size;
533 while( zPath[i]=='/' ){ i++; }
534 pParent = pNew;
535 }
536 while( pParent && pParent->pParent ){
537 if( pParent->pParent->mtime < pParent->mtime ){
@@ -788,46 +791,49 @@
791 */
792 if( zCI ){
793 Stmt q;
794 compute_fileage(rid, 0);
795 db_prepare(&q,
796 "SELECT filename.name, blob.uuid, blob.size, fileage.mtime\n"
797 " FROM fileage, filename, blob\n"
798 " WHERE filename.fnid=fileage.fnid\n"
799 " AND blob.rid=fileage.fid\n"
800 " ORDER BY filename.name COLLATE uintnocase;"
801 );
802 while( db_step(&q)==SQLITE_ROW ){
803 const char *zFile = db_column_text(&q,0);
804 const char *zUuid = db_column_text(&q,1);
805 int size = db_column_int(&q,2);
806 double mtime = db_column_double(&q,3);
807 if( nD>0 && (fossil_strncmp(zFile, zD, nD-1)!=0 || zFile[nD-1]!='/') ){
808 continue;
809 }
810 if( pRE && re_match(pRE, (const unsigned char*)zFile, -1)==0 ) continue;
811 tree_add_node(&sTree, zFile, zUuid, mtime, size);
812 }
813 db_finalize(&q);
814 }else{
815 Stmt q;
816 db_prepare(&q,
817 "SELECT\n"
818 " (SELECT name FROM filename WHERE filename.fnid=mlink.fnid),\n"
819 " (SELECT uuid FROM blob WHERE blob.rid=mlink.fid),\n"
820 " (SELECT size FROM blob WHERE blob.rid=mlink.fid),\n"
821 " max(event.mtime)\n"
822 " FROM mlink JOIN event ON event.objid=mlink.mid\n"
823 " GROUP BY mlink.fnid\n"
824 " ORDER BY 1 COLLATE uintnocase;");
825 while( db_step(&q)==SQLITE_ROW ){
826 const char *zName = db_column_text(&q, 0);
827 const char *zUuid = db_column_text(&q,1);
828 int size = db_column_int(&q,2);
829 double mtime = db_column_double(&q,3);
830 if( nD>0 && (fossil_strncmp(zName, zD, nD-1)!=0 || zName[nD-1]!='/') ){
831 continue;
832 }
833 if( pRE && re_match(pRE, (const u8*)zName, -1)==0 ) continue;
834 tree_add_node(&sTree, zName, zUuid, mtime, size);
835 }
836 db_finalize(&q);
837 }
838 style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
839
@@ -902,10 +908,11 @@
908 @ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
909 @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
910 if( p->mtime>0.0 ){
911 char *zAge = human_readable_age(rNow - p->mtime);
912 @ <div class="filetreeage">%s(zAge)</div>
913 @ <div class="filetreesize"></div>
914 }
915 @ </div>
916 if( startExpanded || (int)(p->nFullName)<=nD ){
917 @ <ul id="dir%d(nDir)">
918 }else{
@@ -923,10 +930,11 @@
930 @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
931 @ %z(zLink)%h(p->zName)</a>
932 if( p->mtime>0 ){
933 char *zAge = human_readable_age(rNow - p->mtime);
934 @ <div class="filetreeage">%s(zAge)</div>
935 @ <div class="filetreesize">%s(p->iSize ? mprintf("%,d",p->iSize) : "-")</div>
936 }
937 @ </div>
938 }
939 if( p->pSibling==0 ){
940 int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
941
+8 -1
--- src/default.css
+++ src/default.css
@@ -332,12 +332,19 @@
332332
v\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo\
333333
+jUs6b5Z/K4siDu5RPUFADs=");
334334
}
335335
div.filetreeage {
336336
display: table-cell;
337
- padding-left: 3em;
337
+ padding-left: 1.5em;
338
+ text-align: right;
339
+ width: 30%;
340
+}
341
+div.filetreesize {
342
+ display: table-cell;
343
+ padding-left: 1em;
338344
text-align: right;
345
+ width: 20%;
339346
}
340347
div.filetreeline:hover {
341348
background-color: #eee;
342349
}
343350
table.login_out {
344351
--- src/default.css
+++ src/default.css
@@ -332,12 +332,19 @@
332 v\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo\
333 +jUs6b5Z/K4siDu5RPUFADs=");
334 }
335 div.filetreeage {
336 display: table-cell;
337 padding-left: 3em;
 
 
 
 
 
 
338 text-align: right;
 
339 }
340 div.filetreeline:hover {
341 background-color: #eee;
342 }
343 table.login_out {
344
--- src/default.css
+++ src/default.css
@@ -332,12 +332,19 @@
332 v\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo\
333 +jUs6b5Z/K4siDu5RPUFADs=");
334 }
335 div.filetreeage {
336 display: table-cell;
337 padding-left: 1.5em;
338 text-align: right;
339 width: 30%;
340 }
341 div.filetreesize {
342 display: table-cell;
343 padding-left: 1em;
344 text-align: right;
345 width: 20%;
346 }
347 div.filetreeline:hover {
348 background-color: #eee;
349 }
350 table.login_out {
351

Keyboard Shortcuts

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