Fossil SCM

Renamed /jtext to /jchunk. Added window.fossil.fetchArtifactLines() to interact with that API.

stephan 2021-09-08 18:17 diff-js-refactoring
Commit 9684425b0c3546e05db09c5dad07b4ccd69b5135cf1a908c12ace261664c5f6d
2 files changed +31 +20 -6
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -20,10 +20,41 @@
2020
document.querySelectorAll('table.diff').forEach(addToggle);
2121
});
2222
2323
window.fossil.onPageLoad(function(){
2424
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
+ };
2556
});
2657
2758
/**
2859
2021-09-07: refactoring the following for use in the higher-level
2960
fossil.*.js framework is pending. For now it's a copy/paste copy
3061
--- 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 @@
18821882
deliver_artifact(rid, P("m"));
18831883
}
18841884
18851885
18861886
/*
1887
-** WEBPAGE: jtext
1888
-** URL: /jtext/HASH?from=N&to=M
1887
+** WEBPAGE: jchunk hidden
1888
+** URL: /jchunk/HASH?from=N&to=M
18891889
**
18901890
** Return lines of text from a file as a JSON array - one entry in the
18911891
** array for each line of text.
18921892
**
18931893
** This page is intended to be used in an XHR from javascript on a diff
@@ -1906,19 +1906,33 @@
19061906
Blob line;
19071907
Blob *pOut;
19081908
19091909
login_check_credentials();
19101910
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. */
19111914
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName);
19121915
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);
19151928
return;
19161929
}
1930
+#endif
19171931
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);
19201934
return;
19211935
}
19221936
content_get(rid, &content);
19231937
g.isConst = 1;
19241938
cgi_set_content_type("text/json");
19251939
--- 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

Keyboard Shortcuts

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