Fossil SCM
Renamed /jtext to /jchunk. Added window.fossil.fetchArtifactLines() to interact with that API.
Commit
9684425b0c3546e05db09c5dad07b4ccd69b5135cf1a908c12ace261664c5f6d
Parent
f68b0b71872b974…
2 files changed
+31
+20
-6
+31
| --- src/fossil.diff.js | ||
| +++ src/fossil.diff.js | ||
| @@ -20,10 +20,41 @@ | ||
| 20 | 20 | document.querySelectorAll('table.diff').forEach(addToggle); |
| 21 | 21 | }); |
| 22 | 22 | |
| 23 | 23 | window.fossil.onPageLoad(function(){ |
| 24 | 24 | const F = window.fossil, D = F.dom; |
| 25 | + | |
| 26 | + /** | |
| 27 | + Uses the /jchunk AJAX route to fetch specific lines of a given | |
| 28 | + artifact. The first argument must be an Object with a minimum of | |
| 29 | + these properties: | |
| 30 | + | |
| 31 | + { | |
| 32 | + name: full hash of the target file, | |
| 33 | + from: first line number of the file to fetch (inclusive), | |
| 34 | + to: last line number of the file to fetch (inclusive) | |
| 35 | + } | |
| 36 | + | |
| 37 | + onload and onerror are optional callback functions to be called | |
| 38 | + on success resp. error, as documented for fossil.fetch(). Note | |
| 39 | + that onload is ostensibly optional but this function is not of | |
| 40 | + much use without an onload handler. Conversely, the default | |
| 41 | + onerror handler is often customized on a per-page basis to send | |
| 42 | + the error output somewhere where the user can see it. | |
| 43 | + | |
| 44 | + The /jchunk route reports errors via JSON objects with | |
| 45 | + an "error" string property describing the problem. | |
| 46 | + | |
| 47 | + This is an async operation. Returns window.fossil. | |
| 48 | + */ | |
| 49 | + F.fetchArtifactLines = function(urlParams, onload, onerror){ | |
| 50 | + const opt = {urlParams}; | |
| 51 | + if(onload) opt.onload = onload; | |
| 52 | + if(onerror) opt.onerror = onerror; | |
| 53 | + F.fetch('jchunk', opt); | |
| 54 | + return F; | |
| 55 | + }; | |
| 25 | 56 | }); |
| 26 | 57 | |
| 27 | 58 | /** |
| 28 | 59 | 2021-09-07: refactoring the following for use in the higher-level |
| 29 | 60 | fossil.*.js framework is pending. For now it's a copy/paste copy |
| 30 | 61 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -20,10 +20,41 @@ | |
| 20 | document.querySelectorAll('table.diff').forEach(addToggle); |
| 21 | }); |
| 22 | |
| 23 | window.fossil.onPageLoad(function(){ |
| 24 | const F = window.fossil, D = F.dom; |
| 25 | }); |
| 26 | |
| 27 | /** |
| 28 | 2021-09-07: refactoring the following for use in the higher-level |
| 29 | fossil.*.js framework is pending. For now it's a copy/paste copy |
| 30 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -20,10 +20,41 @@ | |
| 20 | document.querySelectorAll('table.diff').forEach(addToggle); |
| 21 | }); |
| 22 | |
| 23 | window.fossil.onPageLoad(function(){ |
| 24 | const F = window.fossil, D = F.dom; |
| 25 | |
| 26 | /** |
| 27 | Uses the /jchunk AJAX route to fetch specific lines of a given |
| 28 | artifact. The first argument must be an Object with a minimum of |
| 29 | these properties: |
| 30 | |
| 31 | { |
| 32 | name: full hash of the target file, |
| 33 | from: first line number of the file to fetch (inclusive), |
| 34 | to: last line number of the file to fetch (inclusive) |
| 35 | } |
| 36 | |
| 37 | onload and onerror are optional callback functions to be called |
| 38 | on success resp. error, as documented for fossil.fetch(). Note |
| 39 | that onload is ostensibly optional but this function is not of |
| 40 | much use without an onload handler. Conversely, the default |
| 41 | onerror handler is often customized on a per-page basis to send |
| 42 | the error output somewhere where the user can see it. |
| 43 | |
| 44 | The /jchunk route reports errors via JSON objects with |
| 45 | an "error" string property describing the problem. |
| 46 | |
| 47 | This is an async operation. Returns window.fossil. |
| 48 | */ |
| 49 | F.fetchArtifactLines = function(urlParams, onload, onerror){ |
| 50 | const opt = {urlParams}; |
| 51 | if(onload) opt.onload = onload; |
| 52 | if(onerror) opt.onerror = onerror; |
| 53 | F.fetch('jchunk', opt); |
| 54 | return F; |
| 55 | }; |
| 56 | }); |
| 57 | |
| 58 | /** |
| 59 | 2021-09-07: refactoring the following for use in the higher-level |
| 60 | fossil.*.js framework is pending. For now it's a copy/paste copy |
| 61 |
+20
-6
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1882,12 +1882,12 @@ | ||
| 1882 | 1882 | deliver_artifact(rid, P("m")); |
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | |
| 1886 | 1886 | /* |
| 1887 | -** WEBPAGE: jtext | |
| 1888 | -** URL: /jtext/HASH?from=N&to=M | |
| 1887 | +** WEBPAGE: jchunk hidden | |
| 1888 | +** URL: /jchunk/HASH?from=N&to=M | |
| 1889 | 1889 | ** |
| 1890 | 1890 | ** Return lines of text from a file as a JSON array - one entry in the |
| 1891 | 1891 | ** array for each line of text. |
| 1892 | 1892 | ** |
| 1893 | 1893 | ** This page is intended to be used in an XHR from javascript on a diff |
| @@ -1906,19 +1906,33 @@ | ||
| 1906 | 1906 | Blob line; |
| 1907 | 1907 | Blob *pOut; |
| 1908 | 1908 | |
| 1909 | 1909 | login_check_credentials(); |
| 1910 | 1910 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1911 | +#if 0 | |
| 1912 | + /* Re-enable this block once this code is integrated somewhere into | |
| 1913 | + the UI. */ | |
| 1911 | 1914 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1912 | 1915 | if( rid==0 ){ |
| 1913 | - cgi_set_status(404, "Not Found"); | |
| 1914 | - @ Unknown artifact: "%h(zName)" | |
| 1916 | + ajax_route_error(404, "Unknown artifact: %h", zName); | |
| 1917 | + return; | |
| 1918 | + } | |
| 1919 | +#else | |
| 1920 | + /* This impl is only to simplify "manual" testing via the JS | |
| 1921 | + console. */ | |
| 1922 | + rid = symbolic_name_to_rid(zName, "*"); | |
| 1923 | + if( rid==0 ){ | |
| 1924 | + ajax_route_error(404, "Unknown artifact: %h", zName); | |
| 1925 | + return; | |
| 1926 | + }else if( rid<0 ){ | |
| 1927 | + ajax_route_error(404, "Ambiguous artifact name: %h", zName); | |
| 1915 | 1928 | return; |
| 1916 | 1929 | } |
| 1930 | +#endif | |
| 1917 | 1931 | if( iFrom<1 || iTo<iFrom ){ |
| 1918 | - cgi_set_status(500, "Bad Request"); | |
| 1919 | - @ Invalid line range | |
| 1932 | + ajax_route_error(500, "Invalid line range from=%d, to=%d.", | |
| 1933 | + iFrom, iTo); | |
| 1920 | 1934 | return; |
| 1921 | 1935 | } |
| 1922 | 1936 | content_get(rid, &content); |
| 1923 | 1937 | g.isConst = 1; |
| 1924 | 1938 | cgi_set_content_type("text/json"); |
| 1925 | 1939 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1882,12 +1882,12 @@ | |
| 1882 | deliver_artifact(rid, P("m")); |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | /* |
| 1887 | ** WEBPAGE: jtext |
| 1888 | ** URL: /jtext/HASH?from=N&to=M |
| 1889 | ** |
| 1890 | ** Return lines of text from a file as a JSON array - one entry in the |
| 1891 | ** array for each line of text. |
| 1892 | ** |
| 1893 | ** This page is intended to be used in an XHR from javascript on a diff |
| @@ -1906,19 +1906,33 @@ | |
| 1906 | Blob line; |
| 1907 | Blob *pOut; |
| 1908 | |
| 1909 | login_check_credentials(); |
| 1910 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1911 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1912 | if( rid==0 ){ |
| 1913 | cgi_set_status(404, "Not Found"); |
| 1914 | @ Unknown artifact: "%h(zName)" |
| 1915 | return; |
| 1916 | } |
| 1917 | if( iFrom<1 || iTo<iFrom ){ |
| 1918 | cgi_set_status(500, "Bad Request"); |
| 1919 | @ Invalid line range |
| 1920 | return; |
| 1921 | } |
| 1922 | content_get(rid, &content); |
| 1923 | g.isConst = 1; |
| 1924 | cgi_set_content_type("text/json"); |
| 1925 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1882,12 +1882,12 @@ | |
| 1882 | deliver_artifact(rid, P("m")); |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | /* |
| 1887 | ** WEBPAGE: jchunk hidden |
| 1888 | ** URL: /jchunk/HASH?from=N&to=M |
| 1889 | ** |
| 1890 | ** Return lines of text from a file as a JSON array - one entry in the |
| 1891 | ** array for each line of text. |
| 1892 | ** |
| 1893 | ** This page is intended to be used in an XHR from javascript on a diff |
| @@ -1906,19 +1906,33 @@ | |
| 1906 | Blob line; |
| 1907 | Blob *pOut; |
| 1908 | |
| 1909 | login_check_credentials(); |
| 1910 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1911 | #if 0 |
| 1912 | /* Re-enable this block once this code is integrated somewhere into |
| 1913 | the UI. */ |
| 1914 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1915 | if( rid==0 ){ |
| 1916 | ajax_route_error(404, "Unknown artifact: %h", zName); |
| 1917 | return; |
| 1918 | } |
| 1919 | #else |
| 1920 | /* This impl is only to simplify "manual" testing via the JS |
| 1921 | console. */ |
| 1922 | rid = symbolic_name_to_rid(zName, "*"); |
| 1923 | if( rid==0 ){ |
| 1924 | ajax_route_error(404, "Unknown artifact: %h", zName); |
| 1925 | return; |
| 1926 | }else if( rid<0 ){ |
| 1927 | ajax_route_error(404, "Ambiguous artifact name: %h", zName); |
| 1928 | return; |
| 1929 | } |
| 1930 | #endif |
| 1931 | if( iFrom<1 || iTo<iFrom ){ |
| 1932 | ajax_route_error(500, "Invalid line range from=%d, to=%d.", |
| 1933 | iFrom, iTo); |
| 1934 | return; |
| 1935 | } |
| 1936 | content_get(rid, &content); |
| 1937 | g.isConst = 1; |
| 1938 | cgi_set_content_type("text/json"); |
| 1939 |