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.
Commit
9f3bad83de7eca0bb64f8629655709cbd04a8d1a0065e4d8f948f27c5b6c6862
Parent
3537c75cc3c9bdc…
1 file changed
+26
-5
+26
-5
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1833,12 +1833,12 @@ | ||
| 1833 | 1833 | ** WEBPAGE: file |
| 1834 | 1834 | ** WEBPAGE: whatis |
| 1835 | 1835 | ** |
| 1836 | 1836 | ** Typical usage: |
| 1837 | 1837 | ** |
| 1838 | -** /artifact/SHA1HASH | |
| 1839 | -** /whatis/SHA1HASH | |
| 1838 | +** /artifact/HASH | |
| 1839 | +** /whatis/HASH | |
| 1840 | 1840 | ** /file/NAME |
| 1841 | 1841 | ** |
| 1842 | 1842 | ** Additional query parameters: |
| 1843 | 1843 | ** |
| 1844 | 1844 | ** ln - show line numbers |
| @@ -1851,13 +1851,15 @@ | ||
| 1851 | 1851 | ** filename=NAME - Show information for content file NAME |
| 1852 | 1852 | ** fn=NAME - "fn" is shorthand for "filename" |
| 1853 | 1853 | ** ci=VERSION - The specific check-in to use for "filename=". |
| 1854 | 1854 | ** |
| 1855 | 1855 | ** 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 | |
| 1857 | 1857 | ** /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. | |
| 1859 | 1861 | */ |
| 1860 | 1862 | void artifact_page(void){ |
| 1861 | 1863 | int rid = 0; |
| 1862 | 1864 | Blob content; |
| 1863 | 1865 | const char *zMime; |
| @@ -1877,19 +1879,38 @@ | ||
| 1877 | 1879 | url_initialize(&url, g.zPath); |
| 1878 | 1880 | rid = artifact_from_ci_and_filename(&url); |
| 1879 | 1881 | if( rid==0 ){ |
| 1880 | 1882 | url_add_parameter(&url, "name", zName); |
| 1881 | 1883 | 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 */ | |
| 1883 | 1892 | rid = db_int(0, |
| 1884 | 1893 | "SELECT fid FROM filename, mlink, event" |
| 1885 | 1894 | " WHERE name=%Q" |
| 1886 | 1895 | " AND mlink.fnid=filename.fnid" |
| 1887 | 1896 | " AND event.objid=mlink.mid" |
| 1888 | 1897 | " ORDER BY event.mtime DESC LIMIT 1", |
| 1889 | 1898 | zName |
| 1890 | 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 */ | |
| 1891 | 1912 | if( rid==0 ){ |
| 1892 | 1913 | style_header("No such file"); |
| 1893 | 1914 | @ File '%h(zName)' does not exist in this repository. |
| 1894 | 1915 | style_footer(); |
| 1895 | 1916 | return; |
| 1896 | 1917 |
| --- 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 |