Fossil SCM
Added SBS/unified diff to /fileedit.
Commit
ae8e24d0217191c8bc3debfe2f4b5fedcbac41e0a35a589fcc8b0639d151a642
Parent
67a2bfb0dc85711…
2 files changed
+11
-3
+46
-6
+11
-3
| --- src/default_css.txt | ||
| +++ src/default_css.txt | ||
| @@ -872,17 +872,17 @@ | ||
| 872 | 872 | border-radius: 0.5em; |
| 873 | 873 | border-color: inherit; |
| 874 | 874 | border-width: 1px; |
| 875 | 875 | } |
| 876 | 876 | form.fileedit fieldset > legend { |
| 877 | - margin-left: 1em; | |
| 877 | + margin: 0 0 0 1em; | |
| 878 | + padding: 0 0.5em 0 0.5em; | |
| 878 | 879 | } |
| 879 | 880 | form.fileedit fieldset > div { |
| 880 | - margin: 0 0.25em; | |
| 881 | + margin: 0 0.25em 0.25em 0.25em; | |
| 881 | 882 | } |
| 882 | 883 | form.fileedit fieldset > div > .input-with-label { |
| 883 | - padding: 0.5em; | |
| 884 | 884 | margin: 0.25em 0.5em; |
| 885 | 885 | } |
| 886 | 886 | form.fileedit fieldset > div > button { |
| 887 | 887 | margin: 0.25em 0.5em; |
| 888 | 888 | } |
| @@ -908,10 +908,18 @@ | ||
| 908 | 908 | div.fileedit-preview { |
| 909 | 909 | margin: 0; |
| 910 | 910 | padding: 0; |
| 911 | 911 | } |
| 912 | 912 | .fileedit-preview > div:first-child { |
| 913 | + margin: 1em 0 0 0; | |
| 914 | + border-bottom: 1px dashed; | |
| 915 | +} | |
| 916 | +div.fileedit-diff { | |
| 917 | + margin: 0; | |
| 918 | + padding: 0; | |
| 919 | +} | |
| 920 | +.fileedit-diff > div:first-child { | |
| 913 | 921 | border-bottom: 1px dashed; |
| 914 | 922 | } |
| 915 | 923 | |
| 916 | 924 | .input-with-label { |
| 917 | 925 | border: 1px inset #808080; |
| 918 | 926 |
| --- src/default_css.txt | |
| +++ src/default_css.txt | |
| @@ -872,17 +872,17 @@ | |
| 872 | border-radius: 0.5em; |
| 873 | border-color: inherit; |
| 874 | border-width: 1px; |
| 875 | } |
| 876 | form.fileedit fieldset > legend { |
| 877 | margin-left: 1em; |
| 878 | } |
| 879 | form.fileedit fieldset > div { |
| 880 | margin: 0 0.25em; |
| 881 | } |
| 882 | form.fileedit fieldset > div > .input-with-label { |
| 883 | padding: 0.5em; |
| 884 | margin: 0.25em 0.5em; |
| 885 | } |
| 886 | form.fileedit fieldset > div > button { |
| 887 | margin: 0.25em 0.5em; |
| 888 | } |
| @@ -908,10 +908,18 @@ | |
| 908 | div.fileedit-preview { |
| 909 | margin: 0; |
| 910 | padding: 0; |
| 911 | } |
| 912 | .fileedit-preview > div:first-child { |
| 913 | border-bottom: 1px dashed; |
| 914 | } |
| 915 | |
| 916 | .input-with-label { |
| 917 | border: 1px inset #808080; |
| 918 |
| --- src/default_css.txt | |
| +++ src/default_css.txt | |
| @@ -872,17 +872,17 @@ | |
| 872 | border-radius: 0.5em; |
| 873 | border-color: inherit; |
| 874 | border-width: 1px; |
| 875 | } |
| 876 | form.fileedit fieldset > legend { |
| 877 | margin: 0 0 0 1em; |
| 878 | padding: 0 0.5em 0 0.5em; |
| 879 | } |
| 880 | form.fileedit fieldset > div { |
| 881 | margin: 0 0.25em 0.25em 0.25em; |
| 882 | } |
| 883 | form.fileedit fieldset > div > .input-with-label { |
| 884 | margin: 0.25em 0.5em; |
| 885 | } |
| 886 | form.fileedit fieldset > div > button { |
| 887 | margin: 0.25em 0.5em; |
| 888 | } |
| @@ -908,10 +908,18 @@ | |
| 908 | div.fileedit-preview { |
| 909 | margin: 0; |
| 910 | padding: 0; |
| 911 | } |
| 912 | .fileedit-preview > div:first-child { |
| 913 | margin: 1em 0 0 0; |
| 914 | border-bottom: 1px dashed; |
| 915 | } |
| 916 | div.fileedit-diff { |
| 917 | margin: 0; |
| 918 | padding: 0; |
| 919 | } |
| 920 | .fileedit-diff > div:first-child { |
| 921 | border-bottom: 1px dashed; |
| 922 | } |
| 923 | |
| 924 | .input-with-label { |
| 925 | border: 1px inset #808080; |
| 926 |
+46
-6
| --- src/fileedit.c | ||
| +++ src/fileedit.c | ||
| @@ -1057,10 +1057,45 @@ | ||
| 1057 | 1057 | break; |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | CX("</div><!--.fileedit-preview-->\n"); |
| 1061 | 1061 | } |
| 1062 | + | |
| 1063 | +/* | |
| 1064 | +** Renders diffs for the /fileedit page. pContent is the | |
| 1065 | +** locally-edited content. frid is the RID of the file's blob entry | |
| 1066 | +** from which pContent is based. zManifestUuid is the checkin version | |
| 1067 | +** to which RID belongs - it is purely informational, for labeling the | |
| 1068 | +** diff view. isSbs is true for side-by-side diffs, false for unified. | |
| 1069 | +*/ | |
| 1070 | +static void fileedit_render_diff(Blob * pContent, int frid, | |
| 1071 | + const char * zManifestUuid, | |
| 1072 | + int isSbs){ | |
| 1073 | + Blob orig = empty_blob; | |
| 1074 | + Blob out = empty_blob; | |
| 1075 | + u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG | DIFF_STRIP_EOLCR; | |
| 1076 | + | |
| 1077 | + content_get(frid, &orig); | |
| 1078 | + if(isSbs){ | |
| 1079 | + diffFlags |= DIFF_SIDEBYSIDE; | |
| 1080 | + }else{ | |
| 1081 | + diffFlags |= DIFF_LINENO; | |
| 1082 | + } | |
| 1083 | + text_diff(&orig, pContent, &out, 0, diffFlags); | |
| 1084 | + CX("<div class='fileedit-diff'>"); | |
| 1085 | + CX("<div>Diff <code>[%S]</code> → Local Edits</div>", | |
| 1086 | + zManifestUuid); | |
| 1087 | + if(isSbs){ | |
| 1088 | + CX("%b",&out); | |
| 1089 | + }else{ | |
| 1090 | + CX("<pre class='udiff'>%b</pre>",&out); | |
| 1091 | + } | |
| 1092 | + CX("</div><!--.fileedit-diff-->\n"); | |
| 1093 | + blob_reset(&orig); | |
| 1094 | + blob_reset(&out); | |
| 1095 | + /* Wow, that was *easy*. */ | |
| 1096 | +} | |
| 1062 | 1097 | |
| 1063 | 1098 | /* |
| 1064 | 1099 | ** Outputs a SELECT list from a compile-time list of integers. |
| 1065 | 1100 | ** The vargs must be a list of (const char *, int) pairs, terminated |
| 1066 | 1101 | ** with a single NULL. Each pair is interpreted as... |
| @@ -1156,12 +1191,13 @@ | ||
| 1156 | 1191 | ** form-submission process, and may change with any given revision of |
| 1157 | 1192 | ** this code. |
| 1158 | 1193 | */ |
| 1159 | 1194 | void fileedit_page(){ |
| 1160 | 1195 | enum submit_modes { |
| 1161 | - SUBMIT_NONE = 0, SUBMIT_SAVE = 1, SUBMIT_PREVIEW = 2, | |
| 1162 | - SUBMIT_DIFF = 3 | |
| 1196 | + SUBMIT_NONE = 0, SUBMIT_SAVE, SUBMIT_PREVIEW, | |
| 1197 | + SUBMIT_DIFF_SBS, SUBMIT_DIFF_UNIFIED, | |
| 1198 | + SUBMIT_end /* sentinel for range validation */ | |
| 1163 | 1199 | }; |
| 1164 | 1200 | const char * zFilename = PD("file",P("name")); |
| 1165 | 1201 | /* filename. We'll accept 'name' |
| 1166 | 1202 | because that param is handled |
| 1167 | 1203 | specially by the core. */ |
| @@ -1215,11 +1251,11 @@ | ||
| 1215 | 1251 | return; |
| 1216 | 1252 | } |
| 1217 | 1253 | db_begin_transaction(); |
| 1218 | 1254 | CheckinMiniInfo_init(&cimi); |
| 1219 | 1255 | submitMode = atoi(PD("submit","0")); |
| 1220 | - if(submitMode < SUBMIT_NONE || submitMode > SUBMIT_DIFF){ | |
| 1256 | + if(submitMode < SUBMIT_NONE || submitMode >= SUBMIT_end){ | |
| 1221 | 1257 | submitMode = 0; |
| 1222 | 1258 | } |
| 1223 | 1259 | zFlagCheck = P("comment_mimetype"); |
| 1224 | 1260 | if(zFlagCheck){ |
| 1225 | 1261 | cimi.zCommentMimetype = mprintf("%s",zFlagCheck); |
| @@ -1469,11 +1505,13 @@ | ||
| 1469 | 1505 | "line numbers added to the preview.", |
| 1470 | 1506 | previewLn); |
| 1471 | 1507 | } |
| 1472 | 1508 | } |
| 1473 | 1509 | CX("<button type='submit' name='submit' value='3'>" |
| 1474 | - "Diff (TODO)</button>"); | |
| 1510 | + "Diff (SBS)</button>"); | |
| 1511 | + CX("<button type='submit' name='submit' value='4'>" | |
| 1512 | + "Diff (Unified)</button>"); | |
| 1475 | 1513 | CX("</div></fieldset>"); |
| 1476 | 1514 | |
| 1477 | 1515 | /******* End of form *******/ |
| 1478 | 1516 | CX("</form>\n"); |
| 1479 | 1517 | |
| @@ -1571,12 +1609,14 @@ | ||
| 1571 | 1609 | }else if(SUBMIT_PREVIEW==submitMode){ |
| 1572 | 1610 | int pflags = 0; |
| 1573 | 1611 | if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS; |
| 1574 | 1612 | fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags, |
| 1575 | 1613 | previewRenderMode, previewHtmlHeight); |
| 1576 | - }else if(SUBMIT_DIFF==submitMode/*diff*/){ | |
| 1577 | - fail((&err,"Diff mode is still TODO.")); | |
| 1614 | + }else if(SUBMIT_DIFF_SBS==submitMode | |
| 1615 | + || SUBMIT_DIFF_UNIFIED==submitMode){ | |
| 1616 | + fileedit_render_diff(&cimi.fileContent, frid, cimi.zParentUuid, | |
| 1617 | + SUBMIT_DIFF_SBS==submitMode); | |
| 1578 | 1618 | }else{ |
| 1579 | 1619 | /* Ignore invalid submitMode value */ |
| 1580 | 1620 | goto end_footer; |
| 1581 | 1621 | } |
| 1582 | 1622 | |
| 1583 | 1623 |
| --- src/fileedit.c | |
| +++ src/fileedit.c | |
| @@ -1057,10 +1057,45 @@ | |
| 1057 | break; |
| 1058 | } |
| 1059 | } |
| 1060 | CX("</div><!--.fileedit-preview-->\n"); |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | ** Outputs a SELECT list from a compile-time list of integers. |
| 1065 | ** The vargs must be a list of (const char *, int) pairs, terminated |
| 1066 | ** with a single NULL. Each pair is interpreted as... |
| @@ -1156,12 +1191,13 @@ | |
| 1156 | ** form-submission process, and may change with any given revision of |
| 1157 | ** this code. |
| 1158 | */ |
| 1159 | void fileedit_page(){ |
| 1160 | enum submit_modes { |
| 1161 | SUBMIT_NONE = 0, SUBMIT_SAVE = 1, SUBMIT_PREVIEW = 2, |
| 1162 | SUBMIT_DIFF = 3 |
| 1163 | }; |
| 1164 | const char * zFilename = PD("file",P("name")); |
| 1165 | /* filename. We'll accept 'name' |
| 1166 | because that param is handled |
| 1167 | specially by the core. */ |
| @@ -1215,11 +1251,11 @@ | |
| 1215 | return; |
| 1216 | } |
| 1217 | db_begin_transaction(); |
| 1218 | CheckinMiniInfo_init(&cimi); |
| 1219 | submitMode = atoi(PD("submit","0")); |
| 1220 | if(submitMode < SUBMIT_NONE || submitMode > SUBMIT_DIFF){ |
| 1221 | submitMode = 0; |
| 1222 | } |
| 1223 | zFlagCheck = P("comment_mimetype"); |
| 1224 | if(zFlagCheck){ |
| 1225 | cimi.zCommentMimetype = mprintf("%s",zFlagCheck); |
| @@ -1469,11 +1505,13 @@ | |
| 1469 | "line numbers added to the preview.", |
| 1470 | previewLn); |
| 1471 | } |
| 1472 | } |
| 1473 | CX("<button type='submit' name='submit' value='3'>" |
| 1474 | "Diff (TODO)</button>"); |
| 1475 | CX("</div></fieldset>"); |
| 1476 | |
| 1477 | /******* End of form *******/ |
| 1478 | CX("</form>\n"); |
| 1479 | |
| @@ -1571,12 +1609,14 @@ | |
| 1571 | }else if(SUBMIT_PREVIEW==submitMode){ |
| 1572 | int pflags = 0; |
| 1573 | if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS; |
| 1574 | fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags, |
| 1575 | previewRenderMode, previewHtmlHeight); |
| 1576 | }else if(SUBMIT_DIFF==submitMode/*diff*/){ |
| 1577 | fail((&err,"Diff mode is still TODO.")); |
| 1578 | }else{ |
| 1579 | /* Ignore invalid submitMode value */ |
| 1580 | goto end_footer; |
| 1581 | } |
| 1582 | |
| 1583 |
| --- src/fileedit.c | |
| +++ src/fileedit.c | |
| @@ -1057,10 +1057,45 @@ | |
| 1057 | break; |
| 1058 | } |
| 1059 | } |
| 1060 | CX("</div><!--.fileedit-preview-->\n"); |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | ** Renders diffs for the /fileedit page. pContent is the |
| 1065 | ** locally-edited content. frid is the RID of the file's blob entry |
| 1066 | ** from which pContent is based. zManifestUuid is the checkin version |
| 1067 | ** to which RID belongs - it is purely informational, for labeling the |
| 1068 | ** diff view. isSbs is true for side-by-side diffs, false for unified. |
| 1069 | */ |
| 1070 | static void fileedit_render_diff(Blob * pContent, int frid, |
| 1071 | const char * zManifestUuid, |
| 1072 | int isSbs){ |
| 1073 | Blob orig = empty_blob; |
| 1074 | Blob out = empty_blob; |
| 1075 | u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG | DIFF_STRIP_EOLCR; |
| 1076 | |
| 1077 | content_get(frid, &orig); |
| 1078 | if(isSbs){ |
| 1079 | diffFlags |= DIFF_SIDEBYSIDE; |
| 1080 | }else{ |
| 1081 | diffFlags |= DIFF_LINENO; |
| 1082 | } |
| 1083 | text_diff(&orig, pContent, &out, 0, diffFlags); |
| 1084 | CX("<div class='fileedit-diff'>"); |
| 1085 | CX("<div>Diff <code>[%S]</code> → Local Edits</div>", |
| 1086 | zManifestUuid); |
| 1087 | if(isSbs){ |
| 1088 | CX("%b",&out); |
| 1089 | }else{ |
| 1090 | CX("<pre class='udiff'>%b</pre>",&out); |
| 1091 | } |
| 1092 | CX("</div><!--.fileedit-diff-->\n"); |
| 1093 | blob_reset(&orig); |
| 1094 | blob_reset(&out); |
| 1095 | /* Wow, that was *easy*. */ |
| 1096 | } |
| 1097 | |
| 1098 | /* |
| 1099 | ** Outputs a SELECT list from a compile-time list of integers. |
| 1100 | ** The vargs must be a list of (const char *, int) pairs, terminated |
| 1101 | ** with a single NULL. Each pair is interpreted as... |
| @@ -1156,12 +1191,13 @@ | |
| 1191 | ** form-submission process, and may change with any given revision of |
| 1192 | ** this code. |
| 1193 | */ |
| 1194 | void fileedit_page(){ |
| 1195 | enum submit_modes { |
| 1196 | SUBMIT_NONE = 0, SUBMIT_SAVE, SUBMIT_PREVIEW, |
| 1197 | SUBMIT_DIFF_SBS, SUBMIT_DIFF_UNIFIED, |
| 1198 | SUBMIT_end /* sentinel for range validation */ |
| 1199 | }; |
| 1200 | const char * zFilename = PD("file",P("name")); |
| 1201 | /* filename. We'll accept 'name' |
| 1202 | because that param is handled |
| 1203 | specially by the core. */ |
| @@ -1215,11 +1251,11 @@ | |
| 1251 | return; |
| 1252 | } |
| 1253 | db_begin_transaction(); |
| 1254 | CheckinMiniInfo_init(&cimi); |
| 1255 | submitMode = atoi(PD("submit","0")); |
| 1256 | if(submitMode < SUBMIT_NONE || submitMode >= SUBMIT_end){ |
| 1257 | submitMode = 0; |
| 1258 | } |
| 1259 | zFlagCheck = P("comment_mimetype"); |
| 1260 | if(zFlagCheck){ |
| 1261 | cimi.zCommentMimetype = mprintf("%s",zFlagCheck); |
| @@ -1469,11 +1505,13 @@ | |
| 1505 | "line numbers added to the preview.", |
| 1506 | previewLn); |
| 1507 | } |
| 1508 | } |
| 1509 | CX("<button type='submit' name='submit' value='3'>" |
| 1510 | "Diff (SBS)</button>"); |
| 1511 | CX("<button type='submit' name='submit' value='4'>" |
| 1512 | "Diff (Unified)</button>"); |
| 1513 | CX("</div></fieldset>"); |
| 1514 | |
| 1515 | /******* End of form *******/ |
| 1516 | CX("</form>\n"); |
| 1517 | |
| @@ -1571,12 +1609,14 @@ | |
| 1609 | }else if(SUBMIT_PREVIEW==submitMode){ |
| 1610 | int pflags = 0; |
| 1611 | if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS; |
| 1612 | fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags, |
| 1613 | previewRenderMode, previewHtmlHeight); |
| 1614 | }else if(SUBMIT_DIFF_SBS==submitMode |
| 1615 | || SUBMIT_DIFF_UNIFIED==submitMode){ |
| 1616 | fileedit_render_diff(&cimi.fileContent, frid, cimi.zParentUuid, |
| 1617 | SUBMIT_DIFF_SBS==submitMode); |
| 1618 | }else{ |
| 1619 | /* Ignore invalid submitMode value */ |
| 1620 | goto end_footer; |
| 1621 | } |
| 1622 | |
| 1623 |