Fossil SCM

Use cr/nl instead of just nl at the end of every line on the check-in comment template for windows. Strip out the cr characters before completing the commit.

drh 2008-06-08 19:31 trunk
Commit e976aa6fcbc4a0eae6fd754b81726e67a297ea7d
2 files changed +41 +4
+41
--- src/blob.c
+++ src/blob.c
@@ -835,5 +835,46 @@
835835
blob_reset(&b2);
836836
blob_reset(&b3);
837837
}
838838
printf("ok\n");
839839
}
840
+
841
+/*
842
+** Convert every \n character in the given blob into \r\n.
843
+*/
844
+void blob_add_cr(Blob *p){
845
+ int i, j, n;
846
+ char *z = p->aData;
847
+ for(i=n=0; i<p->nUsed; i++){
848
+ if( z[i]=='\n' ) n++;
849
+ }
850
+ if( p->nUsed+n+1>p->nAlloc ){
851
+ blob_resize(p, p->nUsed+n);
852
+ z = p->aData;
853
+ }
854
+ i = p->nUsed - 1;
855
+ j = i + n;
856
+ while( j>i ){
857
+ z[j--] = z[i];
858
+ if( z[i]=='\n' ){
859
+ z[j--] = '\r';
860
+ }
861
+ i--;
862
+ }
863
+ p->nUsed += n;
864
+ p->aData[p->nUsed] = 0;
865
+}
866
+
867
+/*
868
+** Remove every \r character from the given blob.
869
+*/
870
+void blob_remove_cr(Blob *p){
871
+ int i, j;
872
+ char *z;
873
+ blob_materialize(p);
874
+ z = p->aData;
875
+ for(i=j=0; z[i]; i++){
876
+ if( z[i]!='\r' ) z[j++] = z[i];
877
+ }
878
+ z[j] = 0;
879
+ p->nUsed = j;
880
+}
840881
--- src/blob.c
+++ src/blob.c
@@ -835,5 +835,46 @@
835 blob_reset(&b2);
836 blob_reset(&b3);
837 }
838 printf("ok\n");
839 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
--- src/blob.c
+++ src/blob.c
@@ -835,5 +835,46 @@
835 blob_reset(&b2);
836 blob_reset(&b3);
837 }
838 printf("ok\n");
839 }
840
841 /*
842 ** Convert every \n character in the given blob into \r\n.
843 */
844 void blob_add_cr(Blob *p){
845 int i, j, n;
846 char *z = p->aData;
847 for(i=n=0; i<p->nUsed; i++){
848 if( z[i]=='\n' ) n++;
849 }
850 if( p->nUsed+n+1>p->nAlloc ){
851 blob_resize(p, p->nUsed+n);
852 z = p->aData;
853 }
854 i = p->nUsed - 1;
855 j = i + n;
856 while( j>i ){
857 z[j--] = z[i];
858 if( z[i]=='\n' ){
859 z[j--] = '\r';
860 }
861 i--;
862 }
863 p->nUsed += n;
864 p->aData[p->nUsed] = 0;
865 }
866
867 /*
868 ** Remove every \r character from the given blob.
869 */
870 void blob_remove_cr(Blob *p){
871 int i, j;
872 char *z;
873 blob_materialize(p);
874 z = p->aData;
875 for(i=j=0; z[i]; i++){
876 if( z[i]!='\r' ) z[j++] = z[i];
877 }
878 z[j] = 0;
879 p->nUsed = j;
880 }
881
--- src/checkin.c
+++ src/checkin.c
@@ -245,18 +245,22 @@
245245
if( zEditor==0 ){
246246
zEditor = "ed";
247247
}
248248
zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
249249
g.zLocalRoot);
250
+#ifdef __MINGW32__
251
+ blob_add_cr(&text);
252
+#endif
250253
blob_write_to_file(&text, zFile);
251254
zCmd = mprintf("%s \"%s\"", zEditor, zFile);
252255
printf("%s\n", zCmd);
253256
if( system(zCmd) ){
254257
fossil_panic("editor aborted");
255258
}
256259
blob_reset(&text);
257260
blob_read_from_file(&text, zFile);
261
+ blob_remove_cr(&text);
258262
unlink(zFile);
259263
free(zFile);
260264
blob_zero(pComment);
261265
while( blob_line(&text, &line) ){
262266
int i, n;
263267
--- src/checkin.c
+++ src/checkin.c
@@ -245,18 +245,22 @@
245 if( zEditor==0 ){
246 zEditor = "ed";
247 }
248 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
249 g.zLocalRoot);
 
 
 
250 blob_write_to_file(&text, zFile);
251 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
252 printf("%s\n", zCmd);
253 if( system(zCmd) ){
254 fossil_panic("editor aborted");
255 }
256 blob_reset(&text);
257 blob_read_from_file(&text, zFile);
 
258 unlink(zFile);
259 free(zFile);
260 blob_zero(pComment);
261 while( blob_line(&text, &line) ){
262 int i, n;
263
--- src/checkin.c
+++ src/checkin.c
@@ -245,18 +245,22 @@
245 if( zEditor==0 ){
246 zEditor = "ed";
247 }
248 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
249 g.zLocalRoot);
250 #ifdef __MINGW32__
251 blob_add_cr(&text);
252 #endif
253 blob_write_to_file(&text, zFile);
254 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
255 printf("%s\n", zCmd);
256 if( system(zCmd) ){
257 fossil_panic("editor aborted");
258 }
259 blob_reset(&text);
260 blob_read_from_file(&text, zFile);
261 blob_remove_cr(&text);
262 unlink(zFile);
263 free(zFile);
264 blob_zero(pComment);
265 while( blob_line(&text, &line) ){
266 int i, n;
267

Keyboard Shortcuts

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