Fossil SCM

Augment the fdiff web method to accept a "patch" query parameter and output text/plain if the parameter is present.

drh 2011-02-20 00:12 trunk
Commit c190bcc3ceaa7a726ed3c4f3d3cb66dfdb83037d
1 file changed +34 -20
+34 -20
--- src/info.c
+++ src/info.c
@@ -917,44 +917,58 @@
917917
}
918918
919919
920920
/*
921921
** WEBPAGE: fdiff
922
+** URL: fdiff?v1=UUID&v2=UUID&patch
922923
**
923
-** Two arguments, v1 and v2, are integers. Show the difference between
924
-** the two records.
924
+** Two arguments, v1 and v2, identify the files to be diffed. Show the
925
+** difference between the two artifacts. Generate plaintext if "patch"
926
+** is present.
925927
*/
926928
void diff_page(void){
927929
int v1, v2;
928
- Blob c1, c2, diff;
930
+ int isPatch;
931
+ Blob c1, c2, diff, *pOut;
929932
930933
login_check_credentials();
931934
if( !g.okRead ){ login_needed(); return; }
932935
v1 = name_to_rid_www("v1");
933936
v2 = name_to_rid_www("v2");
934937
if( v1==0 || v2==0 ) fossil_redirect_home();
935
- style_header("Diff");
936
- @ <h2>Differences From:</h2>
937
- @ <blockquote><p>
938
- object_description(v1, 1, 0);
939
- @ </p></blockquote>
940
- @ <h2>To:</h2>
941
- @ <blockquote><p>
942
- object_description(v2, 1, 0);
943
- @ </p></blockquote>
944
- @ <hr />
945
- @ <blockquote><pre>
938
+ isPatch = P("patch")!=0;
939
+ if( isPatch ){
940
+ pOut = cgi_output_blob();
941
+ cgi_set_content_type("text/plain");
942
+ }else{
943
+ blob_zero(&diff);
944
+ pOut = &diff;
945
+ }
946946
content_get(v1, &c1);
947947
content_get(v2, &c2);
948
- blob_zero(&diff);
949
- text_diff(&c1, &c2, &diff, 4, 1);
948
+ text_diff(&c1, &c2, pOut, 4, 1);
950949
blob_reset(&c1);
951950
blob_reset(&c2);
952
- @ %h(blob_str(&diff))
953
- @ </pre></blockquote>
954
- blob_reset(&diff);
955
- style_footer();
951
+ if( !isPatch ){
952
+ style_header("Diff");
953
+ style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
954
+ g.zTop, P("v1"), P("v2"));
955
+ @ <h2>Differences From:</h2>
956
+ @ <blockquote><p>
957
+ object_description(v1, 1, 0);
958
+ @ </p></blockquote>
959
+ @ <h2>To:</h2>
960
+ @ <blockquote><p>
961
+ object_description(v2, 1, 0);
962
+ @ </p></blockquote>
963
+ @ <hr />
964
+ @ <blockquote><pre>
965
+ @ %h(blob_str(&diff))
966
+ @ </pre></blockquote>
967
+ blob_reset(&diff);
968
+ style_footer();
969
+ }
956970
}
957971
958972
/*
959973
** WEBPAGE: raw
960974
** URL: /raw?name=ARTIFACTID&m=TYPE
961975
--- src/info.c
+++ src/info.c
@@ -917,44 +917,58 @@
917 }
918
919
920 /*
921 ** WEBPAGE: fdiff
 
922 **
923 ** Two arguments, v1 and v2, are integers. Show the difference between
924 ** the two records.
 
925 */
926 void diff_page(void){
927 int v1, v2;
928 Blob c1, c2, diff;
 
929
930 login_check_credentials();
931 if( !g.okRead ){ login_needed(); return; }
932 v1 = name_to_rid_www("v1");
933 v2 = name_to_rid_www("v2");
934 if( v1==0 || v2==0 ) fossil_redirect_home();
935 style_header("Diff");
936 @ <h2>Differences From:</h2>
937 @ <blockquote><p>
938 object_description(v1, 1, 0);
939 @ </p></blockquote>
940 @ <h2>To:</h2>
941 @ <blockquote><p>
942 object_description(v2, 1, 0);
943 @ </p></blockquote>
944 @ <hr />
945 @ <blockquote><pre>
946 content_get(v1, &c1);
947 content_get(v2, &c2);
948 blob_zero(&diff);
949 text_diff(&c1, &c2, &diff, 4, 1);
950 blob_reset(&c1);
951 blob_reset(&c2);
952 @ %h(blob_str(&diff))
953 @ </pre></blockquote>
954 blob_reset(&diff);
955 style_footer();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
956 }
957
958 /*
959 ** WEBPAGE: raw
960 ** URL: /raw?name=ARTIFACTID&m=TYPE
961
--- src/info.c
+++ src/info.c
@@ -917,44 +917,58 @@
917 }
918
919
920 /*
921 ** WEBPAGE: fdiff
922 ** URL: fdiff?v1=UUID&v2=UUID&patch
923 **
924 ** Two arguments, v1 and v2, identify the files to be diffed. Show the
925 ** difference between the two artifacts. Generate plaintext if "patch"
926 ** is present.
927 */
928 void diff_page(void){
929 int v1, v2;
930 int isPatch;
931 Blob c1, c2, diff, *pOut;
932
933 login_check_credentials();
934 if( !g.okRead ){ login_needed(); return; }
935 v1 = name_to_rid_www("v1");
936 v2 = name_to_rid_www("v2");
937 if( v1==0 || v2==0 ) fossil_redirect_home();
938 isPatch = P("patch")!=0;
939 if( isPatch ){
940 pOut = cgi_output_blob();
941 cgi_set_content_type("text/plain");
942 }else{
943 blob_zero(&diff);
944 pOut = &diff;
945 }
 
 
 
946 content_get(v1, &c1);
947 content_get(v2, &c2);
948 text_diff(&c1, &c2, pOut, 4, 1);
 
949 blob_reset(&c1);
950 blob_reset(&c2);
951 if( !isPatch ){
952 style_header("Diff");
953 style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
954 g.zTop, P("v1"), P("v2"));
955 @ <h2>Differences From:</h2>
956 @ <blockquote><p>
957 object_description(v1, 1, 0);
958 @ </p></blockquote>
959 @ <h2>To:</h2>
960 @ <blockquote><p>
961 object_description(v2, 1, 0);
962 @ </p></blockquote>
963 @ <hr />
964 @ <blockquote><pre>
965 @ %h(blob_str(&diff))
966 @ </pre></blockquote>
967 blob_reset(&diff);
968 style_footer();
969 }
970 }
971
972 /*
973 ** WEBPAGE: raw
974 ** URL: /raw?name=ARTIFACTID&m=TYPE
975

Keyboard Shortcuts

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