Fossil SCM

Added fix for issue seen with merge; would fail due to file_copy() issue where files of renamed directories would not have the new directory created beforehand. Also added fix for issue seen after large merge; 'changes' command would fail due to WriteConsoleW() returning with error ERROR_NOT_ENOUGH_MEMORY; fix seems hacky but works.

Jeff 2013-02-25 01:02 UTC trunk
Commit 3f31dc65977d999833b85fbe485f11890fb84efe
2 files changed +21 +7 -2
+21
--- src/file.c
+++ src/file.c
@@ -349,10 +349,26 @@
349349
if( z[0]=='/' ) zTail = &z[1];
350350
z++;
351351
}
352352
return zTail;
353353
}
354
+
355
+/*
356
+** Return the head of a file pathname. The head is everything leading up
357
+** to the last component of the path. For example, the head of "/a/b/c.d" is "/a/b".
358
+** The trailing slash is removed.
359
+*/
360
+void file_head(const char *z, char *h){
361
+ int i = file_tail(z)-z;
362
+ if( !i ){
363
+ memmove(h, z, strlen(z));
364
+ return;
365
+ }
366
+ if( '/' == z[i-1] ) i--;
367
+ memmove(h, z, i);
368
+ h[i] = '\0';
369
+}
354370
355371
/*
356372
** Copy the content of a file from one place to another.
357373
*/
358374
void file_copy(const char *zFrom, const char *zTo){
@@ -359,10 +375,15 @@
359375
FILE *in, *out;
360376
int got;
361377
char zBuf[8192];
362378
in = fossil_fopen(zFrom, "rb");
363379
if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
380
+ file_head(zTo, zBuf);
381
+ if( !file_isdir(zBuf) )
382
+ {
383
+ file_mkdir(zBuf, 0);
384
+ }
364385
out = fossil_fopen(zTo, "wb");
365386
if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
366387
while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
367388
fwrite(zBuf, 1, got, out);
368389
}
369390
--- src/file.c
+++ src/file.c
@@ -349,10 +349,26 @@
349 if( z[0]=='/' ) zTail = &z[1];
350 z++;
351 }
352 return zTail;
353 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
355 /*
356 ** Copy the content of a file from one place to another.
357 */
358 void file_copy(const char *zFrom, const char *zTo){
@@ -359,10 +375,15 @@
359 FILE *in, *out;
360 int got;
361 char zBuf[8192];
362 in = fossil_fopen(zFrom, "rb");
363 if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
 
 
 
 
 
364 out = fossil_fopen(zTo, "wb");
365 if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
366 while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
367 fwrite(zBuf, 1, got, out);
368 }
369
--- src/file.c
+++ src/file.c
@@ -349,10 +349,26 @@
349 if( z[0]=='/' ) zTail = &z[1];
350 z++;
351 }
352 return zTail;
353 }
354
355 /*
356 ** Return the head of a file pathname. The head is everything leading up
357 ** to the last component of the path. For example, the head of "/a/b/c.d" is "/a/b".
358 ** The trailing slash is removed.
359 */
360 void file_head(const char *z, char *h){
361 int i = file_tail(z)-z;
362 if( !i ){
363 memmove(h, z, strlen(z));
364 return;
365 }
366 if( '/' == z[i-1] ) i--;
367 memmove(h, z, i);
368 h[i] = '\0';
369 }
370
371 /*
372 ** Copy the content of a file from one place to another.
373 */
374 void file_copy(const char *zFrom, const char *zTo){
@@ -359,10 +375,15 @@
375 FILE *in, *out;
376 int got;
377 char zBuf[8192];
378 in = fossil_fopen(zFrom, "rb");
379 if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
380 file_head(zTo, zBuf);
381 if( !file_isdir(zBuf) )
382 {
383 file_mkdir(zBuf, 0);
384 }
385 out = fossil_fopen(zTo, "wb");
386 if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
387 while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
388 fwrite(zBuf, 1, got, out);
389 }
390
+7 -2
--- src/utf8.c
+++ src/utf8.c
@@ -212,12 +212,17 @@
212212
if( nChar==0 ){
213213
free(zUnicode);
214214
return 0;
215215
}
216216
zUnicode[nChar] = '\0';
217
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar,
218
- &dummy, 0);
217
+ if( 0==WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr),
218
+ zUnicode, nChar, &dummy, 0) ){
219
+ /** print UTF8 to console if all else fails */
220
+ WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr),
221
+ zUtf8, nChar, &dummy, 0);
222
+ }
223
+
219224
return nChar;
220225
#else
221226
return -1; /* No-op on unix */
222227
#endif
223228
}
224229
--- src/utf8.c
+++ src/utf8.c
@@ -212,12 +212,17 @@
212 if( nChar==0 ){
213 free(zUnicode);
214 return 0;
215 }
216 zUnicode[nChar] = '\0';
217 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar,
218 &dummy, 0);
 
 
 
 
 
219 return nChar;
220 #else
221 return -1; /* No-op on unix */
222 #endif
223 }
224
--- src/utf8.c
+++ src/utf8.c
@@ -212,12 +212,17 @@
212 if( nChar==0 ){
213 free(zUnicode);
214 return 0;
215 }
216 zUnicode[nChar] = '\0';
217 if( 0==WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr),
218 zUnicode, nChar, &dummy, 0) ){
219 /** print UTF8 to console if all else fails */
220 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr),
221 zUtf8, nChar, &dummy, 0);
222 }
223
224 return nChar;
225 #else
226 return -1; /* No-op on unix */
227 #endif
228 }
229

Keyboard Shortcuts

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