Fossil SCM

Experimental changes to unified diff output to 'ignore' sections that are purely additions. Still needs SBS support and tests.

mistachkin 2019-01-22 23:19 trunk
Commit 6e3f354de15ad20e636574e4db9bd2b0265f6139848772930f4b2c5374a64f62
+8 -1
--- src/diff.c
+++ src/diff.c
@@ -42,10 +42,11 @@
4242
#define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
4343
#define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
4444
#define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */
4545
#define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */
4646
#define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */
47
+#define DIFF_IGNORE_PADDS (((u64)0x40)<<32) /* Ignore sections of purely adds */
4748
4849
/*
4950
** These error messages are shared in multiple locations. They are defined
5051
** here for consistency.
5152
*/
@@ -351,15 +352,17 @@
351352
int skip; /* Number of lines to skip */
352353
static int nChunk = 0; /* Number of diff chunks seen so far */
353354
int nContext; /* Number of lines of context */
354355
int showLn; /* Show line numbers */
355356
int html; /* Render as HTML */
357
+ int noPureAdds; /* Ignore sections that are purely additions */
356358
int showDivider = 0; /* True to show the divider between diff blocks */
357359
358360
nContext = diff_context_lines(diffFlags);
359361
showLn = (diffFlags & DIFF_LINENO)!=0;
360362
html = (diffFlags & DIFF_HTML)!=0;
363
+ noPureAdds = (diffFlags & DIFF_IGNORE_PADDS)!=0;
361364
A = p->aFrom;
362365
B = p->aTo;
363366
R = p->aEdit;
364367
mxr = p->nEdit;
365368
while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -459,20 +462,24 @@
459462
a += m;
460463
b += m;
461464
462465
/* Show the differences */
463466
for(i=0; i<nr; i++){
467
+ int nDels = 0;
464468
m = R[r+i*3+1];
465469
for(j=0; j<m; j++){
466470
if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html);
467471
appendDiffLine(pOut, '-', &A[a+j], html, pRe);
472
+ nDels++;
468473
}
469474
a += m;
470475
m = R[r+i*3+2];
471476
for(j=0; j<m; j++){
477
+ char cPrefix = '+';
478
+ if( noPureAdds && nDels==0 ) cPrefix = ' ';
472479
if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html);
473
- appendDiffLine(pOut, '+', &B[b+j], html, pRe);
480
+ appendDiffLine(pOut, cPrefix, &B[b+j], html, pRe);
474481
}
475482
b += m;
476483
if( i<nr-1 ){
477484
m = R[r+i*3+3];
478485
for(j=0; j<m; j++){
479486
--- src/diff.c
+++ src/diff.c
@@ -42,10 +42,11 @@
42 #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
43 #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
44 #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */
45 #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */
46 #define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */
 
47
48 /*
49 ** These error messages are shared in multiple locations. They are defined
50 ** here for consistency.
51 */
@@ -351,15 +352,17 @@
351 int skip; /* Number of lines to skip */
352 static int nChunk = 0; /* Number of diff chunks seen so far */
353 int nContext; /* Number of lines of context */
354 int showLn; /* Show line numbers */
355 int html; /* Render as HTML */
 
356 int showDivider = 0; /* True to show the divider between diff blocks */
357
358 nContext = diff_context_lines(diffFlags);
359 showLn = (diffFlags & DIFF_LINENO)!=0;
360 html = (diffFlags & DIFF_HTML)!=0;
 
361 A = p->aFrom;
362 B = p->aTo;
363 R = p->aEdit;
364 mxr = p->nEdit;
365 while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -459,20 +462,24 @@
459 a += m;
460 b += m;
461
462 /* Show the differences */
463 for(i=0; i<nr; i++){
 
464 m = R[r+i*3+1];
465 for(j=0; j<m; j++){
466 if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html);
467 appendDiffLine(pOut, '-', &A[a+j], html, pRe);
 
468 }
469 a += m;
470 m = R[r+i*3+2];
471 for(j=0; j<m; j++){
 
 
472 if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html);
473 appendDiffLine(pOut, '+', &B[b+j], html, pRe);
474 }
475 b += m;
476 if( i<nr-1 ){
477 m = R[r+i*3+3];
478 for(j=0; j<m; j++){
479
--- src/diff.c
+++ src/diff.c
@@ -42,10 +42,11 @@
42 #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
43 #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
44 #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */
45 #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */
46 #define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */
47 #define DIFF_IGNORE_PADDS (((u64)0x40)<<32) /* Ignore sections of purely adds */
48
49 /*
50 ** These error messages are shared in multiple locations. They are defined
51 ** here for consistency.
52 */
@@ -351,15 +352,17 @@
352 int skip; /* Number of lines to skip */
353 static int nChunk = 0; /* Number of diff chunks seen so far */
354 int nContext; /* Number of lines of context */
355 int showLn; /* Show line numbers */
356 int html; /* Render as HTML */
357 int noPureAdds; /* Ignore sections that are purely additions */
358 int showDivider = 0; /* True to show the divider between diff blocks */
359
360 nContext = diff_context_lines(diffFlags);
361 showLn = (diffFlags & DIFF_LINENO)!=0;
362 html = (diffFlags & DIFF_HTML)!=0;
363 noPureAdds = (diffFlags & DIFF_IGNORE_PADDS)!=0;
364 A = p->aFrom;
365 B = p->aTo;
366 R = p->aEdit;
367 mxr = p->nEdit;
368 while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -459,20 +462,24 @@
462 a += m;
463 b += m;
464
465 /* Show the differences */
466 for(i=0; i<nr; i++){
467 int nDels = 0;
468 m = R[r+i*3+1];
469 for(j=0; j<m; j++){
470 if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html);
471 appendDiffLine(pOut, '-', &A[a+j], html, pRe);
472 nDels++;
473 }
474 a += m;
475 m = R[r+i*3+2];
476 for(j=0; j<m; j++){
477 char cPrefix = '+';
478 if( noPureAdds && nDels==0 ) cPrefix = ' ';
479 if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html);
480 appendDiffLine(pOut, cPrefix, &B[b+j], html, pRe);
481 }
482 b += m;
483 if( i<nr-1 ){
484 m = R[r+i*3+3];
485 for(j=0; j<m; j++){
486
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -835,10 +835,11 @@
835835
** --context|-c N Use N lines of context
836836
** --diff-binary BOOL Include binary files when using external commands
837837
** --exec-abs-paths Force absolute path names with external commands.
838838
** --exec-rel-paths Force relative path names with external commands.
839839
** --from|-r VERSION Select VERSION as source for the diff
840
+** --ignore-pure-adds Ignore all sections containing only additions.
840841
** --internal|-i Use internal diff logic
841842
** --new-file|-N Show complete text of added and deleted files
842843
** --numstat Show only the number of lines delete and added
843844
** --side-by-side|-y Side-by-side diff
844845
** --strip-trailing-cr Strip trailing CR
@@ -881,10 +882,11 @@
881882
verboseFlag = find_option("verbose","v",0)!=0;
882883
if( !verboseFlag ){
883884
verboseFlag = find_option("new-file","N",0)!=0; /* deprecated */
884885
}
885886
if( verboseFlag ) diffFlags |= DIFF_VERBOSE;
887
+ if( find_option("ignore-pure-adds",0,0)!=0 ) diffFlags |= DIFF_IGNORE_PADDS;
886888
if( againstUndo && ( zFrom!=0 || zTo!=0 || zCheckin!=0 || zBranch!=0) ){
887889
fossil_fatal("cannot use --undo together with --from, --to, --checkin,"
888890
" or --branch");
889891
}
890892
if( zBranch ){
891893
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -835,10 +835,11 @@
835 ** --context|-c N Use N lines of context
836 ** --diff-binary BOOL Include binary files when using external commands
837 ** --exec-abs-paths Force absolute path names with external commands.
838 ** --exec-rel-paths Force relative path names with external commands.
839 ** --from|-r VERSION Select VERSION as source for the diff
 
840 ** --internal|-i Use internal diff logic
841 ** --new-file|-N Show complete text of added and deleted files
842 ** --numstat Show only the number of lines delete and added
843 ** --side-by-side|-y Side-by-side diff
844 ** --strip-trailing-cr Strip trailing CR
@@ -881,10 +882,11 @@
881 verboseFlag = find_option("verbose","v",0)!=0;
882 if( !verboseFlag ){
883 verboseFlag = find_option("new-file","N",0)!=0; /* deprecated */
884 }
885 if( verboseFlag ) diffFlags |= DIFF_VERBOSE;
 
886 if( againstUndo && ( zFrom!=0 || zTo!=0 || zCheckin!=0 || zBranch!=0) ){
887 fossil_fatal("cannot use --undo together with --from, --to, --checkin,"
888 " or --branch");
889 }
890 if( zBranch ){
891
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -835,10 +835,11 @@
835 ** --context|-c N Use N lines of context
836 ** --diff-binary BOOL Include binary files when using external commands
837 ** --exec-abs-paths Force absolute path names with external commands.
838 ** --exec-rel-paths Force relative path names with external commands.
839 ** --from|-r VERSION Select VERSION as source for the diff
840 ** --ignore-pure-adds Ignore all sections containing only additions.
841 ** --internal|-i Use internal diff logic
842 ** --new-file|-N Show complete text of added and deleted files
843 ** --numstat Show only the number of lines delete and added
844 ** --side-by-side|-y Side-by-side diff
845 ** --strip-trailing-cr Strip trailing CR
@@ -881,10 +882,11 @@
882 verboseFlag = find_option("verbose","v",0)!=0;
883 if( !verboseFlag ){
884 verboseFlag = find_option("new-file","N",0)!=0; /* deprecated */
885 }
886 if( verboseFlag ) diffFlags |= DIFF_VERBOSE;
887 if( find_option("ignore-pure-adds",0,0)!=0 ) diffFlags |= DIFF_IGNORE_PADDS;
888 if( againstUndo && ( zFrom!=0 || zTo!=0 || zCheckin!=0 || zBranch!=0) ){
889 fossil_fatal("cannot use --undo together with --from, --to, --checkin,"
890 " or --branch");
891 }
892 if( zBranch ){
893
+2
--- src/info.c
+++ src/info.c
@@ -1169,10 +1169,11 @@
11691169
** diff=INTEGER 0: none, 1: unified, 2: side-by-side
11701170
** glob=STRING only diff files matching this glob
11711171
** dc=N show N lines of context around each diff
11721172
** w=BOOLEAN ignore whitespace when computing diffs
11731173
** nohdr omit the description at the top of the page
1174
+** nopureadds Ignore all sections containing only additions
11741175
**
11751176
**
11761177
** Show all differences between two check-ins.
11771178
*/
11781179
void vdiff_page(void){
@@ -1210,10 +1211,11 @@
12101211
zTo = P("to");
12111212
if(zGlob && !*zGlob){
12121213
zGlob = NULL;
12131214
}
12141215
diffFlags = construct_diff_flags(diffType);
1216
+ if( P("nopureadds") ) diffFlags |= DIFF_IGNORE_PADDS;
12151217
zW = (diffFlags&DIFF_IGNORE_ALLWS)?"&w":"";
12161218
style_submenu_element("Path", "%R/timeline?me=%T&you=%T", zFrom, zTo);
12171219
if( diffType!=0 ){
12181220
style_submenu_element("Hide Diff", "%R/vdiff?from=%T&to=%T&diff=0%s%T%s",
12191221
zFrom, zTo,
12201222
--- src/info.c
+++ src/info.c
@@ -1169,10 +1169,11 @@
1169 ** diff=INTEGER 0: none, 1: unified, 2: side-by-side
1170 ** glob=STRING only diff files matching this glob
1171 ** dc=N show N lines of context around each diff
1172 ** w=BOOLEAN ignore whitespace when computing diffs
1173 ** nohdr omit the description at the top of the page
 
1174 **
1175 **
1176 ** Show all differences between two check-ins.
1177 */
1178 void vdiff_page(void){
@@ -1210,10 +1211,11 @@
1210 zTo = P("to");
1211 if(zGlob && !*zGlob){
1212 zGlob = NULL;
1213 }
1214 diffFlags = construct_diff_flags(diffType);
 
1215 zW = (diffFlags&DIFF_IGNORE_ALLWS)?"&w":"";
1216 style_submenu_element("Path", "%R/timeline?me=%T&you=%T", zFrom, zTo);
1217 if( diffType!=0 ){
1218 style_submenu_element("Hide Diff", "%R/vdiff?from=%T&to=%T&diff=0%s%T%s",
1219 zFrom, zTo,
1220
--- src/info.c
+++ src/info.c
@@ -1169,10 +1169,11 @@
1169 ** diff=INTEGER 0: none, 1: unified, 2: side-by-side
1170 ** glob=STRING only diff files matching this glob
1171 ** dc=N show N lines of context around each diff
1172 ** w=BOOLEAN ignore whitespace when computing diffs
1173 ** nohdr omit the description at the top of the page
1174 ** nopureadds Ignore all sections containing only additions
1175 **
1176 **
1177 ** Show all differences between two check-ins.
1178 */
1179 void vdiff_page(void){
@@ -1210,10 +1211,11 @@
1211 zTo = P("to");
1212 if(zGlob && !*zGlob){
1213 zGlob = NULL;
1214 }
1215 diffFlags = construct_diff_flags(diffType);
1216 if( P("nopureadds") ) diffFlags |= DIFF_IGNORE_PADDS;
1217 zW = (diffFlags&DIFF_IGNORE_ALLWS)?"&w":"";
1218 style_submenu_element("Path", "%R/timeline?me=%T&you=%T", zFrom, zTo);
1219 if( diffType!=0 ){
1220 style_submenu_element("Hide Diff", "%R/vdiff?from=%T&to=%T&diff=0%s%T%s",
1221 zFrom, zTo,
1222

Keyboard Shortcuts

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