Fossil SCM

Added SBS/unified diff to /fileedit.

stephan 2020-05-04 17:44 checkin-without-checkout
Commit ae8e24d0217191c8bc3debfe2f4b5fedcbac41e0a35a589fcc8b0639d151a642
2 files changed +11 -3 +46 -6
--- src/default_css.txt
+++ src/default_css.txt
@@ -872,17 +872,17 @@
872872
border-radius: 0.5em;
873873
border-color: inherit;
874874
border-width: 1px;
875875
}
876876
form.fileedit fieldset > legend {
877
- margin-left: 1em;
877
+ margin: 0 0 0 1em;
878
+ padding: 0 0.5em 0 0.5em;
878879
}
879880
form.fileedit fieldset > div {
880
- margin: 0 0.25em;
881
+ margin: 0 0.25em 0.25em 0.25em;
881882
}
882883
form.fileedit fieldset > div > .input-with-label {
883
- padding: 0.5em;
884884
margin: 0.25em 0.5em;
885885
}
886886
form.fileedit fieldset > div > button {
887887
margin: 0.25em 0.5em;
888888
}
@@ -908,10 +908,18 @@
908908
div.fileedit-preview {
909909
margin: 0;
910910
padding: 0;
911911
}
912912
.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 {
913921
border-bottom: 1px dashed;
914922
}
915923
916924
.input-with-label {
917925
border: 1px inset #808080;
918926
--- 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 @@
10571057
break;
10581058
}
10591059
}
10601060
CX("</div><!--.fileedit-preview-->\n");
10611061
}
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> &rarr; 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
+}
10621097
10631098
/*
10641099
** Outputs a SELECT list from a compile-time list of integers.
10651100
** The vargs must be a list of (const char *, int) pairs, terminated
10661101
** with a single NULL. Each pair is interpreted as...
@@ -1156,12 +1191,13 @@
11561191
** form-submission process, and may change with any given revision of
11571192
** this code.
11581193
*/
11591194
void fileedit_page(){
11601195
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 */
11631199
};
11641200
const char * zFilename = PD("file",P("name"));
11651201
/* filename. We'll accept 'name'
11661202
because that param is handled
11671203
specially by the core. */
@@ -1215,11 +1251,11 @@
12151251
return;
12161252
}
12171253
db_begin_transaction();
12181254
CheckinMiniInfo_init(&cimi);
12191255
submitMode = atoi(PD("submit","0"));
1220
- if(submitMode < SUBMIT_NONE || submitMode > SUBMIT_DIFF){
1256
+ if(submitMode < SUBMIT_NONE || submitMode >= SUBMIT_end){
12211257
submitMode = 0;
12221258
}
12231259
zFlagCheck = P("comment_mimetype");
12241260
if(zFlagCheck){
12251261
cimi.zCommentMimetype = mprintf("%s",zFlagCheck);
@@ -1469,11 +1505,13 @@
14691505
"line numbers added to the preview.",
14701506
previewLn);
14711507
}
14721508
}
14731509
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>");
14751513
CX("</div></fieldset>");
14761514
14771515
/******* End of form *******/
14781516
CX("</form>\n");
14791517
@@ -1571,12 +1609,14 @@
15711609
}else if(SUBMIT_PREVIEW==submitMode){
15721610
int pflags = 0;
15731611
if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS;
15741612
fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags,
15751613
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);
15781618
}else{
15791619
/* Ignore invalid submitMode value */
15801620
goto end_footer;
15811621
}
15821622
15831623
--- 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> &rarr; 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

Keyboard Shortcuts

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