Fossil SCM
Augment the fdiff web method to accept a "patch" query parameter and output text/plain if the parameter is present.
Commit
c190bcc3ceaa7a726ed3c4f3d3cb66dfdb83037d
Parent
4bdf71b1ce3e16c…
1 file changed
+34
-20
+34
-20
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -917,44 +917,58 @@ | ||
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | |
| 920 | 920 | /* |
| 921 | 921 | ** WEBPAGE: fdiff |
| 922 | +** URL: fdiff?v1=UUID&v2=UUID&patch | |
| 922 | 923 | ** |
| 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. | |
| 925 | 927 | */ |
| 926 | 928 | void diff_page(void){ |
| 927 | 929 | int v1, v2; |
| 928 | - Blob c1, c2, diff; | |
| 930 | + int isPatch; | |
| 931 | + Blob c1, c2, diff, *pOut; | |
| 929 | 932 | |
| 930 | 933 | login_check_credentials(); |
| 931 | 934 | if( !g.okRead ){ login_needed(); return; } |
| 932 | 935 | v1 = name_to_rid_www("v1"); |
| 933 | 936 | v2 = name_to_rid_www("v2"); |
| 934 | 937 | 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 | + } | |
| 946 | 946 | content_get(v1, &c1); |
| 947 | 947 | content_get(v2, &c2); |
| 948 | - blob_zero(&diff); | |
| 949 | - text_diff(&c1, &c2, &diff, 4, 1); | |
| 948 | + text_diff(&c1, &c2, pOut, 4, 1); | |
| 950 | 949 | blob_reset(&c1); |
| 951 | 950 | 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 | + } | |
| 956 | 970 | } |
| 957 | 971 | |
| 958 | 972 | /* |
| 959 | 973 | ** WEBPAGE: raw |
| 960 | 974 | ** URL: /raw?name=ARTIFACTID&m=TYPE |
| 961 | 975 |
| --- 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 |