Fossil SCM

Internally rearranged how diff flags are passed around, in anticipation of having to refactor for wiki/forum diffs. Added annotate/blame links to /fileedit's first tab.

stephan 2020-05-15 04:20 fileedit-ajaxify
Commit 39a5241b6f7e1035e2d7bdb373e49cf830e85970cfac4d4a248278745ded4905
+45 -11
--- src/fileedit.c
+++ src/fileedit.c
@@ -1004,18 +1004,19 @@
10041004
** to which RID belongs - it is purely informational, for labeling the
10051005
** diff view. isSbs is true for side-by-side diffs, false for unified.
10061006
*/
10071007
static void fileedit_render_diff(Blob * pContent, int frid,
10081008
const char * zManifestUuid,
1009
- int isSbs){
1009
+ u64 diffFlags){
10101010
Blob orig = empty_blob;
10111011
Blob out = empty_blob;
1012
- u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG | DIFF_STRIP_EOLCR
1013
- | (isSbs ? DIFF_SIDEBYSIDE : DIFF_LINENO);
1012
+
10141013
content_get(frid, &orig);
10151014
text_diff(&orig, pContent, &out, 0, diffFlags);
1016
- if(isSbs || blob_size(&out)==0){
1015
+ if(blob_size(&out)==0){
1016
+ /* nothing to do */
1017
+ }else if(DIFF_SIDEBYSIDE & diffFlags){
10171018
CX("%b",&out);
10181019
}else{
10191020
CX("<pre class='udiff'>%b</pre>",&out);
10201021
}
10211022
blob_reset(&orig);
@@ -1308,10 +1309,15 @@
13081309
** checkin=checkin version
13091310
**
13101311
** Optional parameters:
13111312
**
13121313
** sbs=integer (1=side-by-side or 0=unified, default=0)
1314
+**
1315
+** ws=integer (0=diff whitespace, 1=ignore EOL ws, 2=ignore all ws)
1316
+**
1317
+** Reminder to self: search info.c for isPatch to see how a
1318
+** patch-style siff can be produced.
13131319
**
13141320
** User must have Write access to use this page.
13151321
**
13161322
** Responds with the HTML content of the diff. On error it produces a
13171323
** JSON response as documented for fileedit_ajax_error().
@@ -1325,14 +1331,27 @@
13251331
*/
13261332
const char * zFilename = 0;
13271333
const char * zRev = 0;
13281334
const char * zContent = P("content");
13291335
char * zRevUuid = 0;
1330
- int isSbs = atoi(PD("sbs","0"));
1331
- int vid, frid;
1336
+ int vid, frid, iFlag;
1337
+ u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG;
13321338
Blob content = empty_blob;
13331339
1340
+ iFlag = atoi(PD("sbs","0"));
1341
+ if(0==iFlag){
1342
+ diffFlags |= DIFF_LINENO;
1343
+ }else{
1344
+ diffFlags |= DIFF_SIDEBYSIDE;
1345
+ }
1346
+ iFlag = atoi(PD("ws","2"));
1347
+ if(2==iFlag){
1348
+ diffFlags |= DIFF_IGNORE_ALLWS;
1349
+ }else if(1==iFlag){
1350
+ diffFlags |= DIFF_IGNORE_EOLWS;
1351
+ }
1352
+ diffFlags |= DIFF_STRIP_EOLCR;
13341353
fileedit_get_fnci_args( &zFilename, &zRev );
13351354
if(!fileedit_ajax_boostrap()
13361355
|| !fileedit_ajax_setup_filerev(zRev, &zRevUuid, &vid,
13371356
zFilename, &frid)){
13381357
return;
@@ -1340,11 +1359,11 @@
13401359
if(!zContent){
13411360
zContent = "";
13421361
}
13431362
cgi_set_content_type("text/html");
13441363
blob_init(&content, zContent, -1);
1345
- fileedit_render_diff(&content, frid, zRevUuid, isSbs);
1364
+ fileedit_render_diff(&content, frid, zRevUuid, diffFlags);
13461365
fossil_free(zRevUuid);
13471366
blob_reset(&content);
13481367
}
13491368
13501369
/*
@@ -1898,14 +1917,29 @@
18981917
"data-tab-parent='fileedit-tabs' "
18991918
"data-tab-label='Diff'"
19001919
">");
19011920
19021921
CX("<div class='fileedit-options flex-container flex-row' "
1903
- "id='fileedit-tab-diff-buttons'>"
1904
- "<button class='sbs'>Side-by-side</button>"
1905
- "<button class='unified'>Unified</button>"
1906
- "</div>");
1922
+ "id='fileedit-tab-diff-buttons'>");
1923
+ CX("<button class='sbs'>Side-by-side</button>"
1924
+ "<button class='unified'>Unified</button>");
1925
+ if(0){
1926
+ /* For the time being let's just ignore all whitespace
1927
+ ** changes, as files with Windows-style EOLs always show
1928
+ ** more diffs than we want then they're submitted to
1929
+ ** ?ajax=diff because JS normalizes them to Unix EOLs.
1930
+ ** We can revisit this decision later. */
1931
+ style_select_list_int("diff-ws-policy",
1932
+ "diff_ws", "Whitespace",
1933
+ "Whitespace handling policy.",
1934
+ 2,
1935
+ "Diff all whitespace", 0,
1936
+ "Ignore EOL whitespace", 1,
1937
+ "Ignore all whitespace", 2,
1938
+ NULL);
1939
+ }
1940
+ CX("</div>");
19071941
CX("<div id='fileedit-tab-diff-wrapper'>"
19081942
"Diffs will be shown here."
19091943
"</div>");
19101944
CX("</div>"/*#fileedit-tab-diff*/);
19111945
}
19121946
--- src/fileedit.c
+++ src/fileedit.c
@@ -1004,18 +1004,19 @@
1004 ** to which RID belongs - it is purely informational, for labeling the
1005 ** diff view. isSbs is true for side-by-side diffs, false for unified.
1006 */
1007 static void fileedit_render_diff(Blob * pContent, int frid,
1008 const char * zManifestUuid,
1009 int isSbs){
1010 Blob orig = empty_blob;
1011 Blob out = empty_blob;
1012 u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG | DIFF_STRIP_EOLCR
1013 | (isSbs ? DIFF_SIDEBYSIDE : DIFF_LINENO);
1014 content_get(frid, &orig);
1015 text_diff(&orig, pContent, &out, 0, diffFlags);
1016 if(isSbs || blob_size(&out)==0){
 
 
1017 CX("%b",&out);
1018 }else{
1019 CX("<pre class='udiff'>%b</pre>",&out);
1020 }
1021 blob_reset(&orig);
@@ -1308,10 +1309,15 @@
1308 ** checkin=checkin version
1309 **
1310 ** Optional parameters:
1311 **
1312 ** sbs=integer (1=side-by-side or 0=unified, default=0)
 
 
 
 
 
1313 **
1314 ** User must have Write access to use this page.
1315 **
1316 ** Responds with the HTML content of the diff. On error it produces a
1317 ** JSON response as documented for fileedit_ajax_error().
@@ -1325,14 +1331,27 @@
1325 */
1326 const char * zFilename = 0;
1327 const char * zRev = 0;
1328 const char * zContent = P("content");
1329 char * zRevUuid = 0;
1330 int isSbs = atoi(PD("sbs","0"));
1331 int vid, frid;
1332 Blob content = empty_blob;
1333
 
 
 
 
 
 
 
 
 
 
 
 
 
1334 fileedit_get_fnci_args( &zFilename, &zRev );
1335 if(!fileedit_ajax_boostrap()
1336 || !fileedit_ajax_setup_filerev(zRev, &zRevUuid, &vid,
1337 zFilename, &frid)){
1338 return;
@@ -1340,11 +1359,11 @@
1340 if(!zContent){
1341 zContent = "";
1342 }
1343 cgi_set_content_type("text/html");
1344 blob_init(&content, zContent, -1);
1345 fileedit_render_diff(&content, frid, zRevUuid, isSbs);
1346 fossil_free(zRevUuid);
1347 blob_reset(&content);
1348 }
1349
1350 /*
@@ -1898,14 +1917,29 @@
1898 "data-tab-parent='fileedit-tabs' "
1899 "data-tab-label='Diff'"
1900 ">");
1901
1902 CX("<div class='fileedit-options flex-container flex-row' "
1903 "id='fileedit-tab-diff-buttons'>"
1904 "<button class='sbs'>Side-by-side</button>"
1905 "<button class='unified'>Unified</button>"
1906 "</div>");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1907 CX("<div id='fileedit-tab-diff-wrapper'>"
1908 "Diffs will be shown here."
1909 "</div>");
1910 CX("</div>"/*#fileedit-tab-diff*/);
1911 }
1912
--- src/fileedit.c
+++ src/fileedit.c
@@ -1004,18 +1004,19 @@
1004 ** to which RID belongs - it is purely informational, for labeling the
1005 ** diff view. isSbs is true for side-by-side diffs, false for unified.
1006 */
1007 static void fileedit_render_diff(Blob * pContent, int frid,
1008 const char * zManifestUuid,
1009 u64 diffFlags){
1010 Blob orig = empty_blob;
1011 Blob out = empty_blob;
1012
 
1013 content_get(frid, &orig);
1014 text_diff(&orig, pContent, &out, 0, diffFlags);
1015 if(blob_size(&out)==0){
1016 /* nothing to do */
1017 }else if(DIFF_SIDEBYSIDE & diffFlags){
1018 CX("%b",&out);
1019 }else{
1020 CX("<pre class='udiff'>%b</pre>",&out);
1021 }
1022 blob_reset(&orig);
@@ -1308,10 +1309,15 @@
1309 ** checkin=checkin version
1310 **
1311 ** Optional parameters:
1312 **
1313 ** sbs=integer (1=side-by-side or 0=unified, default=0)
1314 **
1315 ** ws=integer (0=diff whitespace, 1=ignore EOL ws, 2=ignore all ws)
1316 **
1317 ** Reminder to self: search info.c for isPatch to see how a
1318 ** patch-style siff can be produced.
1319 **
1320 ** User must have Write access to use this page.
1321 **
1322 ** Responds with the HTML content of the diff. On error it produces a
1323 ** JSON response as documented for fileedit_ajax_error().
@@ -1325,14 +1331,27 @@
1331 */
1332 const char * zFilename = 0;
1333 const char * zRev = 0;
1334 const char * zContent = P("content");
1335 char * zRevUuid = 0;
1336 int vid, frid, iFlag;
1337 u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG;
1338 Blob content = empty_blob;
1339
1340 iFlag = atoi(PD("sbs","0"));
1341 if(0==iFlag){
1342 diffFlags |= DIFF_LINENO;
1343 }else{
1344 diffFlags |= DIFF_SIDEBYSIDE;
1345 }
1346 iFlag = atoi(PD("ws","2"));
1347 if(2==iFlag){
1348 diffFlags |= DIFF_IGNORE_ALLWS;
1349 }else if(1==iFlag){
1350 diffFlags |= DIFF_IGNORE_EOLWS;
1351 }
1352 diffFlags |= DIFF_STRIP_EOLCR;
1353 fileedit_get_fnci_args( &zFilename, &zRev );
1354 if(!fileedit_ajax_boostrap()
1355 || !fileedit_ajax_setup_filerev(zRev, &zRevUuid, &vid,
1356 zFilename, &frid)){
1357 return;
@@ -1340,11 +1359,11 @@
1359 if(!zContent){
1360 zContent = "";
1361 }
1362 cgi_set_content_type("text/html");
1363 blob_init(&content, zContent, -1);
1364 fileedit_render_diff(&content, frid, zRevUuid, diffFlags);
1365 fossil_free(zRevUuid);
1366 blob_reset(&content);
1367 }
1368
1369 /*
@@ -1898,14 +1917,29 @@
1917 "data-tab-parent='fileedit-tabs' "
1918 "data-tab-label='Diff'"
1919 ">");
1920
1921 CX("<div class='fileedit-options flex-container flex-row' "
1922 "id='fileedit-tab-diff-buttons'>");
1923 CX("<button class='sbs'>Side-by-side</button>"
1924 "<button class='unified'>Unified</button>");
1925 if(0){
1926 /* For the time being let's just ignore all whitespace
1927 ** changes, as files with Windows-style EOLs always show
1928 ** more diffs than we want then they're submitted to
1929 ** ?ajax=diff because JS normalizes them to Unix EOLs.
1930 ** We can revisit this decision later. */
1931 style_select_list_int("diff-ws-policy",
1932 "diff_ws", "Whitespace",
1933 "Whitespace handling policy.",
1934 2,
1935 "Diff all whitespace", 0,
1936 "Ignore EOL whitespace", 1,
1937 "Ignore all whitespace", 2,
1938 NULL);
1939 }
1940 CX("</div>");
1941 CX("<div id='fileedit-tab-diff-wrapper'>"
1942 "Diffs will be shown here."
1943 "</div>");
1944 CX("</div>"/*#fileedit-tab-diff*/);
1945 }
1946
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -119,16 +119,15 @@
119119
D.clearElement(selFiles, this.e.btnLoadFile);
120120
D.append(
121121
D.clearElement(this.e.fileListLabel),
122122
"Editable files for ",
123123
D.append(
124
- D.code(),
124
+ D.code(), "[",
125125
D.a(F.repoUrl('timeline',{
126126
c: ciUuid
127
- }), F.hashDigits(ciUuid)),
128
- ),
129
- ":"
127
+ }), F.hashDigits(ciUuid)),"]"
128
+ ), ":"
130129
);
131130
this.cache.files[response.checkin] = response;
132131
response.editableFiles.forEach(function(fn,n){
133132
D.option(selFiles, fn);
134133
});
@@ -242,10 +241,11 @@
242241
selectPreviewMode: E('#select-preview-mode select'),
243242
selectHtmlEmsWrap: E('#select-preview-html-ems'),
244243
selectEolWrap: E('#select-eol-style'),
245244
selectEol: E('#select-eol-style select[name=eol]'),
246245
selectFontSizeWrap: E('#select-font-size'),
246
+ selectDiffWS: E('select[name=diff_ws]'),
247247
cbLineNumbersWrap: E('#cb-line-numbers'),
248248
cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
249249
previewTarget: E('#fileedit-tab-preview-wrapper'),
250250
cbIsExe: E('input[type=checkbox][name=exec_bit]'),
251251
fsFileVersionDetails: E('#file-version-details'),
@@ -498,27 +498,38 @@
498498
D.append(D.code(),
499499
D.a(F.repoUrl('finfo',{name:file, m:rUrl}), file)),
500500
D.br()
501501
);
502502
D.append(
503
- eTgt, "Checkin Version: ",
503
+ eTgt, "Checkin: ",
504504
D.append(D.code(), D.a(F.repoUrl('info/'+rUrl), rHuman)),
505505
" [",D.a(F.repoUrl('timeline',{m:rUrl}), "timeline"),"]",
506506
D.br()
507507
);
508508
D.append(
509509
eTgt, "Mimetype: ",
510510
D.append(D.code(), this.finfo.mimetype||'???'),
511511
D.br()
512512
);
513
+ D.append(
514
+ eTgt,
515
+ D.append(D.code(), "[",
516
+ D.a(F.repoUrl('annotate',{filename:file, checkin:rUrl}),
517
+ 'annotate'), "]"),
518
+ D.append(D.code(), "[",
519
+ D.a(F.repoUrl('blame',{filename:file, checkin:rUrl}),
520
+ 'blame'), "]")
521
+ );
513522
const purlArgs = F.encodeUrlArgs({
514523
filename: this.finfo.filename,
515524
checkin: rUrl
516525
},false,true);
517526
const purl = F.repoUrl('fileedit',purlArgs);
518527
D.append(
519
- eTgt,"[",D.a(purl,"Editor permalink"),"]"
528
+ eTgt,
529
+ D.append(D.code(),
530
+ "[",D.a(purl,"Editor permalink"),"]")
520531
);
521532
this.setPageTitle("Edit: "+this.finfo.filename);
522533
return this;
523534
};
524535
@@ -659,10 +670,11 @@
659670
const fd = new FormData();
660671
fd.append('filename',this.finfo.filename);
661672
fd.append('checkin', this.finfo.checkin);
662673
fd.append('sbs', sbs ? 1 : 0);
663674
fd.append('content',content);
675
+ if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
664676
F.message(
665677
"Fetching diff..."
666678
).fetch('fileedit',{
667679
urlParams: {ajax: 'diff'},
668680
payload: fd,
669681
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -119,16 +119,15 @@
119 D.clearElement(selFiles, this.e.btnLoadFile);
120 D.append(
121 D.clearElement(this.e.fileListLabel),
122 "Editable files for ",
123 D.append(
124 D.code(),
125 D.a(F.repoUrl('timeline',{
126 c: ciUuid
127 }), F.hashDigits(ciUuid)),
128 ),
129 ":"
130 );
131 this.cache.files[response.checkin] = response;
132 response.editableFiles.forEach(function(fn,n){
133 D.option(selFiles, fn);
134 });
@@ -242,10 +241,11 @@
242 selectPreviewMode: E('#select-preview-mode select'),
243 selectHtmlEmsWrap: E('#select-preview-html-ems'),
244 selectEolWrap: E('#select-eol-style'),
245 selectEol: E('#select-eol-style select[name=eol]'),
246 selectFontSizeWrap: E('#select-font-size'),
 
247 cbLineNumbersWrap: E('#cb-line-numbers'),
248 cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
249 previewTarget: E('#fileedit-tab-preview-wrapper'),
250 cbIsExe: E('input[type=checkbox][name=exec_bit]'),
251 fsFileVersionDetails: E('#file-version-details'),
@@ -498,27 +498,38 @@
498 D.append(D.code(),
499 D.a(F.repoUrl('finfo',{name:file, m:rUrl}), file)),
500 D.br()
501 );
502 D.append(
503 eTgt, "Checkin Version: ",
504 D.append(D.code(), D.a(F.repoUrl('info/'+rUrl), rHuman)),
505 " [",D.a(F.repoUrl('timeline',{m:rUrl}), "timeline"),"]",
506 D.br()
507 );
508 D.append(
509 eTgt, "Mimetype: ",
510 D.append(D.code(), this.finfo.mimetype||'???'),
511 D.br()
512 );
 
 
 
 
 
 
 
 
 
513 const purlArgs = F.encodeUrlArgs({
514 filename: this.finfo.filename,
515 checkin: rUrl
516 },false,true);
517 const purl = F.repoUrl('fileedit',purlArgs);
518 D.append(
519 eTgt,"[",D.a(purl,"Editor permalink"),"]"
 
 
520 );
521 this.setPageTitle("Edit: "+this.finfo.filename);
522 return this;
523 };
524
@@ -659,10 +670,11 @@
659 const fd = new FormData();
660 fd.append('filename',this.finfo.filename);
661 fd.append('checkin', this.finfo.checkin);
662 fd.append('sbs', sbs ? 1 : 0);
663 fd.append('content',content);
 
664 F.message(
665 "Fetching diff..."
666 ).fetch('fileedit',{
667 urlParams: {ajax: 'diff'},
668 payload: fd,
669
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -119,16 +119,15 @@
119 D.clearElement(selFiles, this.e.btnLoadFile);
120 D.append(
121 D.clearElement(this.e.fileListLabel),
122 "Editable files for ",
123 D.append(
124 D.code(), "[",
125 D.a(F.repoUrl('timeline',{
126 c: ciUuid
127 }), F.hashDigits(ciUuid)),"]"
128 ), ":"
 
129 );
130 this.cache.files[response.checkin] = response;
131 response.editableFiles.forEach(function(fn,n){
132 D.option(selFiles, fn);
133 });
@@ -242,10 +241,11 @@
241 selectPreviewMode: E('#select-preview-mode select'),
242 selectHtmlEmsWrap: E('#select-preview-html-ems'),
243 selectEolWrap: E('#select-eol-style'),
244 selectEol: E('#select-eol-style select[name=eol]'),
245 selectFontSizeWrap: E('#select-font-size'),
246 selectDiffWS: E('select[name=diff_ws]'),
247 cbLineNumbersWrap: E('#cb-line-numbers'),
248 cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
249 previewTarget: E('#fileedit-tab-preview-wrapper'),
250 cbIsExe: E('input[type=checkbox][name=exec_bit]'),
251 fsFileVersionDetails: E('#file-version-details'),
@@ -498,27 +498,38 @@
498 D.append(D.code(),
499 D.a(F.repoUrl('finfo',{name:file, m:rUrl}), file)),
500 D.br()
501 );
502 D.append(
503 eTgt, "Checkin: ",
504 D.append(D.code(), D.a(F.repoUrl('info/'+rUrl), rHuman)),
505 " [",D.a(F.repoUrl('timeline',{m:rUrl}), "timeline"),"]",
506 D.br()
507 );
508 D.append(
509 eTgt, "Mimetype: ",
510 D.append(D.code(), this.finfo.mimetype||'???'),
511 D.br()
512 );
513 D.append(
514 eTgt,
515 D.append(D.code(), "[",
516 D.a(F.repoUrl('annotate',{filename:file, checkin:rUrl}),
517 'annotate'), "]"),
518 D.append(D.code(), "[",
519 D.a(F.repoUrl('blame',{filename:file, checkin:rUrl}),
520 'blame'), "]")
521 );
522 const purlArgs = F.encodeUrlArgs({
523 filename: this.finfo.filename,
524 checkin: rUrl
525 },false,true);
526 const purl = F.repoUrl('fileedit',purlArgs);
527 D.append(
528 eTgt,
529 D.append(D.code(),
530 "[",D.a(purl,"Editor permalink"),"]")
531 );
532 this.setPageTitle("Edit: "+this.finfo.filename);
533 return this;
534 };
535
@@ -659,10 +670,11 @@
670 const fd = new FormData();
671 fd.append('filename',this.finfo.filename);
672 fd.append('checkin', this.finfo.checkin);
673 fd.append('sbs', sbs ? 1 : 0);
674 fd.append('content',content);
675 if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
676 F.message(
677 "Fetching diff..."
678 ).fetch('fileedit',{
679 urlParams: {ajax: 'diff'},
680 payload: fd,
681

Keyboard Shortcuts

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