Fossil SCM

Change the built-in "diff" so that it no longer ignores whitespace at the end of lines, as doing so confuses the "patch" command. Ticket [a9f7b23c2e376af5b0]

drh 2010-08-21 03:33 trunk
Commit 7f788bdb045c8e149fec1ab7f36b9a3faee8e3f8
1 file changed +4 -2
+4 -2
--- src/diff.c
+++ src/diff.c
@@ -65,11 +65,13 @@
6565
/*
6666
** Return an array of DLine objects containing a pointer to the
6767
** start of each line and a hash of that line. The lower
6868
** bits of the hash store the length of each line.
6969
**
70
-** Trailing whitespace is removed from each line.
70
+** Trailing whitespace is removed from each line. 2010-08-20: Not any
71
+** more. If trailing whitespace is ignored, the "patch" command gets
72
+** confused by the diff output. Ticket [a9f7b23c2e376af5b0e5b]
7173
**
7274
** Return 0 if the file is binary or contains a line that is
7375
** too long.
7476
*/
7577
static DLine *break_into_lines(const char *z, int n, int *pnLine){
@@ -102,11 +104,11 @@
102104
103105
/* Fill in the array */
104106
for(i=0; i<nLine; i++){
105107
a[i].z = z;
106108
for(j=0; z[j] && z[j]!='\n'; j++){}
107
- for(k=j; k>0 && isspace(z[k-1]); k--){}
109
+ for(k=j; k>0 && isspace(z[k-1]); k--){break;}
108110
for(h=0, x=0; x<k; x++){
109111
h = h ^ (h<<2) ^ z[x];
110112
}
111113
a[i].h = h = (h<<LENGTH_MASK_SZ) | k;;
112114
h2 = h % nLine;
113115
--- src/diff.c
+++ src/diff.c
@@ -65,11 +65,13 @@
65 /*
66 ** Return an array of DLine objects containing a pointer to the
67 ** start of each line and a hash of that line. The lower
68 ** bits of the hash store the length of each line.
69 **
70 ** Trailing whitespace is removed from each line.
 
 
71 **
72 ** Return 0 if the file is binary or contains a line that is
73 ** too long.
74 */
75 static DLine *break_into_lines(const char *z, int n, int *pnLine){
@@ -102,11 +104,11 @@
102
103 /* Fill in the array */
104 for(i=0; i<nLine; i++){
105 a[i].z = z;
106 for(j=0; z[j] && z[j]!='\n'; j++){}
107 for(k=j; k>0 && isspace(z[k-1]); k--){}
108 for(h=0, x=0; x<k; x++){
109 h = h ^ (h<<2) ^ z[x];
110 }
111 a[i].h = h = (h<<LENGTH_MASK_SZ) | k;;
112 h2 = h % nLine;
113
--- src/diff.c
+++ src/diff.c
@@ -65,11 +65,13 @@
65 /*
66 ** Return an array of DLine objects containing a pointer to the
67 ** start of each line and a hash of that line. The lower
68 ** bits of the hash store the length of each line.
69 **
70 ** Trailing whitespace is removed from each line. 2010-08-20: Not any
71 ** more. If trailing whitespace is ignored, the "patch" command gets
72 ** confused by the diff output. Ticket [a9f7b23c2e376af5b0e5b]
73 **
74 ** Return 0 if the file is binary or contains a line that is
75 ** too long.
76 */
77 static DLine *break_into_lines(const char *z, int n, int *pnLine){
@@ -102,11 +104,11 @@
104
105 /* Fill in the array */
106 for(i=0; i<nLine; i++){
107 a[i].z = z;
108 for(j=0; z[j] && z[j]!='\n'; j++){}
109 for(k=j; k>0 && isspace(z[k-1]); k--){break;}
110 for(h=0, x=0; x<k; x++){
111 h = h ^ (h<<2) ^ z[x];
112 }
113 a[i].h = h = (h<<LENGTH_MASK_SZ) | k;;
114 h2 = h % nLine;
115

Keyboard Shortcuts

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