Fossil SCM

Fix the display of all web-pages which contain annotation- or diff-like sections for the case windows-style line endings are used: The CR's should be stripped in those cases.

jan.nijtmans 2014-03-16 10:33 UTC trunk
Commit 1472cd811f29b1a5ebd8050b2d135fa50208b59f
2 files changed +8 -7 +1 -1
+8 -7
--- src/diff.c
+++ src/diff.c
@@ -40,10 +40,11 @@
4040
#define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */
4141
#define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
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 */
45
+#define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */
4546
4647
/*
4748
** These error messages are shared in multiple locations. They are defined
4849
** here for consistency.
4950
*/
@@ -165,10 +166,13 @@
165166
166167
/* Fill in the array */
167168
for(i=0; i<nLine; i++){
168169
for(j=0; z[j] && z[j]!='\n'; j++){}
169170
a[i].z = z;
171
+ if( diffFlags & DIFF_STRIP_EOLCR ){
172
+ if( k>0 && z[k-1]=='\r' ){ k--; }
173
+ }
170174
a[i].n = k = j;
171175
s = 0;
172176
if( diffFlags & DIFF_IGNORE_EOLWS ){
173177
while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
174178
}
@@ -227,21 +231,18 @@
227231
int html, /* True if generating HTML. False for plain text */
228232
ReCompiled *pRe /* Colorize only if line matches this Regex */
229233
){
230234
blob_append(pOut, &cPrefix, 1);
231235
if( html ){
232
- int n;
233236
if( pRe && re_dline_match(pRe, pLine, 1)==0 ){
234237
cPrefix = ' ';
235238
}else if( cPrefix=='+' ){
236239
blob_append(pOut, "<span class=\"diffadd\">", -1);
237240
}else if( cPrefix=='-' ){
238241
blob_append(pOut, "<span class=\"diffrm\">", -1);
239242
}
240
- n = pLine->n;
241
- while( n>0 && (pLine->z[n-1]=='\n' || pLine->z[n-1]=='\r') ) n--;
242
- htmlize_to_blob(pOut, pLine->z, n);
243
+ htmlize_to_blob(pOut, pLine->z, pLine->n);
243244
if( cPrefix!=' ' ){
244245
blob_append(pOut, "</span>", -1);
245246
}
246247
}else{
247248
blob_append(pOut, pLine->z, pLine->n);
@@ -1957,11 +1958,11 @@
19571958
typedef struct Annotator Annotator;
19581959
struct Annotator {
19591960
DContext c; /* The diff-engine context */
19601961
struct AnnLine { /* Lines of the original files... */
19611962
const char *z; /* The text of the line */
1962
- short int n; /* Number of bytes (omitting trailing space and \n) */
1963
+ short int n; /* Number of bytes (omitting trailing \n) */
19631964
short int iVers; /* Level at which tag was set */
19641965
} *aOrig;
19651966
int nOrig; /* Number of elements in aOrig[] */
19661967
int nVers; /* Number of versions analyzed */
19671968
int bLimit; /* True if the iLimit was reached */
@@ -2171,11 +2172,11 @@
21712172
void annotation_page(void){
21722173
int mid;
21732174
int fnid;
21742175
int i;
21752176
int iLimit; /* Depth limit */
2176
- u64 annFlags = ANN_FILE_ANCEST;
2177
+ u64 annFlags = (ANN_FILE_ANCEST|DIFF_STRIP_EOLCR);
21772178
int showLog = 0; /* True to display the log */
21782179
int ignoreWs = 0; /* Ignore whitespace */
21792180
const char *zFilename; /* Name of file to annotate */
21802181
const char *zCI; /* The check-in containing zFilename */
21812182
Annotator ann;
@@ -2407,11 +2408,11 @@
24072408
" ORDER BY ancestor.generation ASC LIMIT 1",
24082409
fid, fnid);
24092410
if( mid==0 ){
24102411
fossil_fatal("unable to find manifest");
24112412
}
2412
- annFlags |= ANN_FILE_ANCEST;
2413
+ annFlags |= (ANN_FILE_ANCEST|DIFF_STRIP_EOLCR);
24132414
annotate_file(&ann, fnid, mid, iLimit, annFlags);
24142415
if( showLog ){
24152416
struct AnnVers *p;
24162417
for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
24172418
fossil_print("version %3d: %s %.10s file %.10s\n",
24182419
--- src/diff.c
+++ src/diff.c
@@ -40,10 +40,11 @@
40 #define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */
41 #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
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
46 /*
47 ** These error messages are shared in multiple locations. They are defined
48 ** here for consistency.
49 */
@@ -165,10 +166,13 @@
165
166 /* Fill in the array */
167 for(i=0; i<nLine; i++){
168 for(j=0; z[j] && z[j]!='\n'; j++){}
169 a[i].z = z;
 
 
 
170 a[i].n = k = j;
171 s = 0;
172 if( diffFlags & DIFF_IGNORE_EOLWS ){
173 while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
174 }
@@ -227,21 +231,18 @@
227 int html, /* True if generating HTML. False for plain text */
228 ReCompiled *pRe /* Colorize only if line matches this Regex */
229 ){
230 blob_append(pOut, &cPrefix, 1);
231 if( html ){
232 int n;
233 if( pRe && re_dline_match(pRe, pLine, 1)==0 ){
234 cPrefix = ' ';
235 }else if( cPrefix=='+' ){
236 blob_append(pOut, "<span class=\"diffadd\">", -1);
237 }else if( cPrefix=='-' ){
238 blob_append(pOut, "<span class=\"diffrm\">", -1);
239 }
240 n = pLine->n;
241 while( n>0 && (pLine->z[n-1]=='\n' || pLine->z[n-1]=='\r') ) n--;
242 htmlize_to_blob(pOut, pLine->z, n);
243 if( cPrefix!=' ' ){
244 blob_append(pOut, "</span>", -1);
245 }
246 }else{
247 blob_append(pOut, pLine->z, pLine->n);
@@ -1957,11 +1958,11 @@
1957 typedef struct Annotator Annotator;
1958 struct Annotator {
1959 DContext c; /* The diff-engine context */
1960 struct AnnLine { /* Lines of the original files... */
1961 const char *z; /* The text of the line */
1962 short int n; /* Number of bytes (omitting trailing space and \n) */
1963 short int iVers; /* Level at which tag was set */
1964 } *aOrig;
1965 int nOrig; /* Number of elements in aOrig[] */
1966 int nVers; /* Number of versions analyzed */
1967 int bLimit; /* True if the iLimit was reached */
@@ -2171,11 +2172,11 @@
2171 void annotation_page(void){
2172 int mid;
2173 int fnid;
2174 int i;
2175 int iLimit; /* Depth limit */
2176 u64 annFlags = ANN_FILE_ANCEST;
2177 int showLog = 0; /* True to display the log */
2178 int ignoreWs = 0; /* Ignore whitespace */
2179 const char *zFilename; /* Name of file to annotate */
2180 const char *zCI; /* The check-in containing zFilename */
2181 Annotator ann;
@@ -2407,11 +2408,11 @@
2407 " ORDER BY ancestor.generation ASC LIMIT 1",
2408 fid, fnid);
2409 if( mid==0 ){
2410 fossil_fatal("unable to find manifest");
2411 }
2412 annFlags |= ANN_FILE_ANCEST;
2413 annotate_file(&ann, fnid, mid, iLimit, annFlags);
2414 if( showLog ){
2415 struct AnnVers *p;
2416 for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
2417 fossil_print("version %3d: %s %.10s file %.10s\n",
2418
--- src/diff.c
+++ src/diff.c
@@ -40,10 +40,11 @@
40 #define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */
41 #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
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
47 /*
48 ** These error messages are shared in multiple locations. They are defined
49 ** here for consistency.
50 */
@@ -165,10 +166,13 @@
166
167 /* Fill in the array */
168 for(i=0; i<nLine; i++){
169 for(j=0; z[j] && z[j]!='\n'; j++){}
170 a[i].z = z;
171 if( diffFlags & DIFF_STRIP_EOLCR ){
172 if( k>0 && z[k-1]=='\r' ){ k--; }
173 }
174 a[i].n = k = j;
175 s = 0;
176 if( diffFlags & DIFF_IGNORE_EOLWS ){
177 while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
178 }
@@ -227,21 +231,18 @@
231 int html, /* True if generating HTML. False for plain text */
232 ReCompiled *pRe /* Colorize only if line matches this Regex */
233 ){
234 blob_append(pOut, &cPrefix, 1);
235 if( html ){
 
236 if( pRe && re_dline_match(pRe, pLine, 1)==0 ){
237 cPrefix = ' ';
238 }else if( cPrefix=='+' ){
239 blob_append(pOut, "<span class=\"diffadd\">", -1);
240 }else if( cPrefix=='-' ){
241 blob_append(pOut, "<span class=\"diffrm\">", -1);
242 }
243 htmlize_to_blob(pOut, pLine->z, pLine->n);
 
 
244 if( cPrefix!=' ' ){
245 blob_append(pOut, "</span>", -1);
246 }
247 }else{
248 blob_append(pOut, pLine->z, pLine->n);
@@ -1957,11 +1958,11 @@
1958 typedef struct Annotator Annotator;
1959 struct Annotator {
1960 DContext c; /* The diff-engine context */
1961 struct AnnLine { /* Lines of the original files... */
1962 const char *z; /* The text of the line */
1963 short int n; /* Number of bytes (omitting trailing \n) */
1964 short int iVers; /* Level at which tag was set */
1965 } *aOrig;
1966 int nOrig; /* Number of elements in aOrig[] */
1967 int nVers; /* Number of versions analyzed */
1968 int bLimit; /* True if the iLimit was reached */
@@ -2171,11 +2172,11 @@
2172 void annotation_page(void){
2173 int mid;
2174 int fnid;
2175 int i;
2176 int iLimit; /* Depth limit */
2177 u64 annFlags = (ANN_FILE_ANCEST|DIFF_STRIP_EOLCR);
2178 int showLog = 0; /* True to display the log */
2179 int ignoreWs = 0; /* Ignore whitespace */
2180 const char *zFilename; /* Name of file to annotate */
2181 const char *zCI; /* The check-in containing zFilename */
2182 Annotator ann;
@@ -2407,11 +2408,11 @@
2408 " ORDER BY ancestor.generation ASC LIMIT 1",
2409 fid, fnid);
2410 if( mid==0 ){
2411 fossil_fatal("unable to find manifest");
2412 }
2413 annFlags |= (ANN_FILE_ANCEST|DIFF_STRIP_EOLCR);
2414 annotate_file(&ann, fnid, mid, iLimit, annFlags);
2415 if( showLog ){
2416 struct AnnVers *p;
2417 for(p=ann.aVers, i=0; i<ann.nVers; i++, p++){
2418 fossil_print("version %3d: %s %.10s file %.10s\n",
2419
+1 -1
--- src/info.c
+++ src/info.c
@@ -470,11 +470,11 @@
470470
diffFlags += x;
471471
472472
/* The "noopt" parameter disables diff optimization */
473473
if( PD("noopt",0)!=0 ) diffFlags |= DIFF_NOOPT;
474474
}
475
- return diffFlags;
475
+ return diffFlags|DIFF_STRIP_EOLCR;
476476
}
477477
478478
/*
479479
** WEBPAGE: vinfo
480480
** WEBPAGE: ci
481481
--- src/info.c
+++ src/info.c
@@ -470,11 +470,11 @@
470 diffFlags += x;
471
472 /* The "noopt" parameter disables diff optimization */
473 if( PD("noopt",0)!=0 ) diffFlags |= DIFF_NOOPT;
474 }
475 return diffFlags;
476 }
477
478 /*
479 ** WEBPAGE: vinfo
480 ** WEBPAGE: ci
481
--- src/info.c
+++ src/info.c
@@ -470,11 +470,11 @@
470 diffFlags += x;
471
472 /* The "noopt" parameter disables diff optimization */
473 if( PD("noopt",0)!=0 ) diffFlags |= DIFF_NOOPT;
474 }
475 return diffFlags|DIFF_STRIP_EOLCR;
476 }
477
478 /*
479 ** WEBPAGE: vinfo
480 ** WEBPAGE: ci
481

Keyboard Shortcuts

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