Fossil SCM

Enhance the /file/NAME page so that it shows directory listings if the NAME argument is a directory instead of a file. If NAME is omitted, it shows all the files at the top-level.

drh 2017-03-15 15:43 trunk
Commit 9f3bad83de7eca0bb64f8629655709cbd04a8d1a0065e4d8f948f27c5b6c6862
1 file changed +26 -5
+26 -5
--- src/info.c
+++ src/info.c
@@ -1833,12 +1833,12 @@
18331833
** WEBPAGE: file
18341834
** WEBPAGE: whatis
18351835
**
18361836
** Typical usage:
18371837
**
1838
-** /artifact/SHA1HASH
1839
-** /whatis/SHA1HASH
1838
+** /artifact/HASH
1839
+** /whatis/HASH
18401840
** /file/NAME
18411841
**
18421842
** Additional query parameters:
18431843
**
18441844
** ln - show line numbers
@@ -1851,13 +1851,15 @@
18511851
** filename=NAME - Show information for content file NAME
18521852
** fn=NAME - "fn" is shorthand for "filename"
18531853
** ci=VERSION - The specific check-in to use for "filename=".
18541854
**
18551855
** The /artifact page show the complete content of a file
1856
-** identified by SHA1HASH as preformatted text. The
1856
+** identified by HASH as preformatted text. The
18571857
** /whatis page shows only a description of the file. The /file
1858
-** page shows the most recent version of the named file.
1858
+** page shows the most recent version of the file or directory
1859
+** called NAME, or a list of the top-level directory if NAME is
1860
+** omitted.
18591861
*/
18601862
void artifact_page(void){
18611863
int rid = 0;
18621864
Blob content;
18631865
const char *zMime;
@@ -1877,19 +1879,38 @@
18771879
url_initialize(&url, g.zPath);
18781880
rid = artifact_from_ci_and_filename(&url);
18791881
if( rid==0 ){
18801882
url_add_parameter(&url, "name", zName);
18811883
if( isFile ){
1882
- if( zName==0 ) zName = "";
1884
+ /* Do a top-level directory listing in /file mode if no argument
1885
+ ** specified */
1886
+ if( zName==0 || zName[0]==0 ){
1887
+ if( P("ci")==0 ) cgi_set_query_parameter("ci","tip");
1888
+ page_tree();
1889
+ return;
1890
+ }
1891
+ /* Look for a single file with the given name */
18831892
rid = db_int(0,
18841893
"SELECT fid FROM filename, mlink, event"
18851894
" WHERE name=%Q"
18861895
" AND mlink.fnid=filename.fnid"
18871896
" AND event.objid=mlink.mid"
18881897
" ORDER BY event.mtime DESC LIMIT 1",
18891898
zName
18901899
);
1900
+ /* If no file called NAME exists, instead look for a directory
1901
+ ** with that name, and do a directory listing */
1902
+ if( rid==0 && db_exists(
1903
+ "SELECT 1 FROM filename"
1904
+ " WHERE name GLOB '%q/*' AND substr(name,1,length(%Q)+1)=='%q/';",
1905
+ zName, zName, zName
1906
+ ) ){
1907
+ if( P("ci")==0 ) cgi_set_query_parameter("ci","tip");
1908
+ page_tree();
1909
+ return;
1910
+ }
1911
+ /* If no file or directory called NAME: issue an error */
18911912
if( rid==0 ){
18921913
style_header("No such file");
18931914
@ File '%h(zName)' does not exist in this repository.
18941915
style_footer();
18951916
return;
18961917
--- src/info.c
+++ src/info.c
@@ -1833,12 +1833,12 @@
1833 ** WEBPAGE: file
1834 ** WEBPAGE: whatis
1835 **
1836 ** Typical usage:
1837 **
1838 ** /artifact/SHA1HASH
1839 ** /whatis/SHA1HASH
1840 ** /file/NAME
1841 **
1842 ** Additional query parameters:
1843 **
1844 ** ln - show line numbers
@@ -1851,13 +1851,15 @@
1851 ** filename=NAME - Show information for content file NAME
1852 ** fn=NAME - "fn" is shorthand for "filename"
1853 ** ci=VERSION - The specific check-in to use for "filename=".
1854 **
1855 ** The /artifact page show the complete content of a file
1856 ** identified by SHA1HASH as preformatted text. The
1857 ** /whatis page shows only a description of the file. The /file
1858 ** page shows the most recent version of the named file.
 
 
1859 */
1860 void artifact_page(void){
1861 int rid = 0;
1862 Blob content;
1863 const char *zMime;
@@ -1877,19 +1879,38 @@
1877 url_initialize(&url, g.zPath);
1878 rid = artifact_from_ci_and_filename(&url);
1879 if( rid==0 ){
1880 url_add_parameter(&url, "name", zName);
1881 if( isFile ){
1882 if( zName==0 ) zName = "";
 
 
 
 
 
 
 
1883 rid = db_int(0,
1884 "SELECT fid FROM filename, mlink, event"
1885 " WHERE name=%Q"
1886 " AND mlink.fnid=filename.fnid"
1887 " AND event.objid=mlink.mid"
1888 " ORDER BY event.mtime DESC LIMIT 1",
1889 zName
1890 );
 
 
 
 
 
 
 
 
 
 
 
 
1891 if( rid==0 ){
1892 style_header("No such file");
1893 @ File '%h(zName)' does not exist in this repository.
1894 style_footer();
1895 return;
1896
--- src/info.c
+++ src/info.c
@@ -1833,12 +1833,12 @@
1833 ** WEBPAGE: file
1834 ** WEBPAGE: whatis
1835 **
1836 ** Typical usage:
1837 **
1838 ** /artifact/HASH
1839 ** /whatis/HASH
1840 ** /file/NAME
1841 **
1842 ** Additional query parameters:
1843 **
1844 ** ln - show line numbers
@@ -1851,13 +1851,15 @@
1851 ** filename=NAME - Show information for content file NAME
1852 ** fn=NAME - "fn" is shorthand for "filename"
1853 ** ci=VERSION - The specific check-in to use for "filename=".
1854 **
1855 ** The /artifact page show the complete content of a file
1856 ** identified by HASH as preformatted text. The
1857 ** /whatis page shows only a description of the file. The /file
1858 ** page shows the most recent version of the file or directory
1859 ** called NAME, or a list of the top-level directory if NAME is
1860 ** omitted.
1861 */
1862 void artifact_page(void){
1863 int rid = 0;
1864 Blob content;
1865 const char *zMime;
@@ -1877,19 +1879,38 @@
1879 url_initialize(&url, g.zPath);
1880 rid = artifact_from_ci_and_filename(&url);
1881 if( rid==0 ){
1882 url_add_parameter(&url, "name", zName);
1883 if( isFile ){
1884 /* Do a top-level directory listing in /file mode if no argument
1885 ** specified */
1886 if( zName==0 || zName[0]==0 ){
1887 if( P("ci")==0 ) cgi_set_query_parameter("ci","tip");
1888 page_tree();
1889 return;
1890 }
1891 /* Look for a single file with the given name */
1892 rid = db_int(0,
1893 "SELECT fid FROM filename, mlink, event"
1894 " WHERE name=%Q"
1895 " AND mlink.fnid=filename.fnid"
1896 " AND event.objid=mlink.mid"
1897 " ORDER BY event.mtime DESC LIMIT 1",
1898 zName
1899 );
1900 /* If no file called NAME exists, instead look for a directory
1901 ** with that name, and do a directory listing */
1902 if( rid==0 && db_exists(
1903 "SELECT 1 FROM filename"
1904 " WHERE name GLOB '%q/*' AND substr(name,1,length(%Q)+1)=='%q/';",
1905 zName, zName, zName
1906 ) ){
1907 if( P("ci")==0 ) cgi_set_query_parameter("ci","tip");
1908 page_tree();
1909 return;
1910 }
1911 /* If no file or directory called NAME: issue an error */
1912 if( rid==0 ){
1913 style_header("No such file");
1914 @ File '%h(zName)' does not exist in this repository.
1915 style_footer();
1916 return;
1917

Keyboard Shortcuts

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