Fossil SCM

Make sure diff output is flushed to screen in a timely manner.

drh 2012-02-04 14:58 trunk
Commit dc96d73dd06ef75e8e18b168080cdd84b2cc0f5c
2 files changed +17 -29 +1
+17 -29
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -19,32 +19,17 @@
1919
*/
2020
#include "config.h"
2121
#include "diffcmd.h"
2222
#include <assert.h>
2323
24
-/*
25
-** Output the results of a diff. Output goes to stdout for command-line
26
-** or to the CGI/HTTP result buffer for web pages.
27
-*/
28
-static void diff_printf(const char *zFormat, ...){
29
- va_list ap;
30
- va_start(ap, zFormat);
31
- if( g.cgiOutput ){
32
- cgi_vprintf(zFormat, ap);
33
- }else{
34
- vprintf(zFormat, ap);
35
- }
36
- va_end(ap);
37
-}
38
-
3924
/*
4025
** Print the "Index:" message that patches wants to see at the top of a diff.
4126
*/
4227
void diff_print_index(const char *zFile, int diffFlags){
4328
if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
4429
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
45
- diff_printf("%s", z);
30
+ fossil_print("%s", z);
4631
fossil_free(z);
4732
}
4833
}
4934
5035
/*
@@ -61,11 +46,11 @@
6146
z = mprintf("%.*c %.*s %.*c\n",
6247
x/2, '=', n1, zLeft, (x+1)/2, '=');
6348
}else{
6449
z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
6550
}
66
- diff_printf("%s", z);
51
+ fossil_print("%s", z);
6752
fossil_free(z);
6853
}
6954
7055
/*
7156
** Show the difference between two files, one in memory and one on disk.
@@ -104,11 +89,11 @@
10489
/* Compute and output the differences */
10590
blob_zero(&out);
10691
text_diff(pFile1, &file2, &out, diffFlags);
10792
if( blob_size(&out) ){
10893
diff_print_filenames(zName, zName2, diffFlags);
109
- diff_printf("%s\n", blob_str(&out));
94
+ fossil_print("%s\n", blob_str(&out));
11095
}
11196
11297
/* Release memory resources */
11398
blob_reset(&file2);
11499
blob_reset(&out);
@@ -163,11 +148,11 @@
163148
Blob out; /* Diff output text */
164149
165150
blob_zero(&out);
166151
text_diff(pFile1, pFile2, &out, diffFlags);
167152
diff_print_filenames(zName, zName, diffFlags);
168
- diff_printf("%s\n", blob_str(&out));
153
+ fossil_print("%s\n", blob_str(&out));
169154
170155
/* Release memory resources */
171156
blob_reset(&out);
172157
}else{
173158
Blob cmd;
@@ -211,11 +196,12 @@
211196
Blob content;
212197
int isLink;
213198
file_tree_name(zFileTreeName, &fname, 1);
214199
historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
215200
if( !isLink != !file_wd_islink(zFrom) ){
216
- diff_printf("cannot compute difference between symlink and regular file\n");
201
+ fossil_print("cannot compute difference between "
202
+ "symlink and regular file\n");
217203
}else{
218204
diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, diffFlags);
219205
}
220206
blob_reset(&content);
221207
blob_reset(&fname);
@@ -287,30 +273,31 @@
287273
int isLink = db_column_int(&q, 5);
288274
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
289275
char *zToFree = zFullName;
290276
int showDiff = 1;
291277
if( isDeleted ){
292
- diff_printf("DELETED %s\n", zPathname);
278
+ fossil_print("DELETED %s\n", zPathname);
293279
if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
294280
}else if( file_access(zFullName, 0) ){
295
- diff_printf("MISSING %s\n", zPathname);
281
+ fossil_print("MISSING %s\n", zPathname);
296282
if( !asNewFile ){ showDiff = 0; }
297283
}else if( isNew ){
298
- diff_printf("ADDED %s\n", zPathname);
284
+ fossil_print("ADDED %s\n", zPathname);
299285
srcid = 0;
300286
if( !asNewFile ){ showDiff = 0; }
301287
}else if( isChnged==3 ){
302
- diff_printf("ADDED_BY_MERGE %s\n", zPathname);
288
+ fossil_print("ADDED_BY_MERGE %s\n", zPathname);
303289
srcid = 0;
304290
if( !asNewFile ){ showDiff = 0; }
305291
}
306292
if( showDiff ){
307293
Blob content;
308294
if( !isLink != !file_wd_islink(zFullName) ){
309295
diff_print_index(zPathname, diffFlags);
310296
diff_print_filenames(zPathname, zPathname, diffFlags);
311
- diff_printf("cannot compute difference between symlink and regular file\n");
297
+ fossil_print("cannot compute difference between "
298
+ "symlink and regular file\n");
312299
continue;
313300
}
314301
if( srcid>0 ){
315302
content_get(srcid, &content);
316303
}else{
@@ -345,11 +332,12 @@
345332
zName = blob_str(&fname);
346333
historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
347334
historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
348335
if( isLink1 != isLink2 ){
349336
diff_print_filenames(zName, zName, diffFlags);
350
- diff_printf("cannot compute difference between symlink and regular file\n");
337
+ fossil_print("cannot compute difference "
338
+ " between symlink and regular file\n");
351339
}else{
352340
diff_file_mem(&v1, &v2, zName, zDiffCmd, diffFlags);
353341
}
354342
blob_reset(&v1);
355343
blob_reset(&v2);
@@ -415,27 +403,27 @@
415403
cmp = -1;
416404
}else{
417405
cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
418406
}
419407
if( cmp<0 ){
420
- diff_printf("DELETED %s\n", pFromFile->zName);
408
+ fossil_print("DELETED %s\n", pFromFile->zName);
421409
if( asNewFlag ){
422410
diff_manifest_entry(pFromFile, 0, zDiffCmd, diffFlags);
423411
}
424412
pFromFile = manifest_file_next(pFrom,0);
425413
}else if( cmp>0 ){
426
- diff_printf("ADDED %s\n", pToFile->zName);
414
+ fossil_print("ADDED %s\n", pToFile->zName);
427415
if( asNewFlag ){
428416
diff_manifest_entry(0, pToFile, zDiffCmd, diffFlags);
429417
}
430418
pToFile = manifest_file_next(pTo,0);
431419
}else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
432420
/* No changes */
433421
pFromFile = manifest_file_next(pFrom,0);
434422
pToFile = manifest_file_next(pTo,0);
435423
}else{
436
- /* diff_printf("CHANGED %s\n", pFromFile->zName); */
424
+ /* fossil_print("CHANGED %s\n", pFromFile->zName); */
437425
diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
438426
pFromFile = manifest_file_next(pFrom,0);
439427
pToFile = manifest_file_next(pTo,0);
440428
}
441429
}
442430
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -19,32 +19,17 @@
19 */
20 #include "config.h"
21 #include "diffcmd.h"
22 #include <assert.h>
23
24 /*
25 ** Output the results of a diff. Output goes to stdout for command-line
26 ** or to the CGI/HTTP result buffer for web pages.
27 */
28 static void diff_printf(const char *zFormat, ...){
29 va_list ap;
30 va_start(ap, zFormat);
31 if( g.cgiOutput ){
32 cgi_vprintf(zFormat, ap);
33 }else{
34 vprintf(zFormat, ap);
35 }
36 va_end(ap);
37 }
38
39 /*
40 ** Print the "Index:" message that patches wants to see at the top of a diff.
41 */
42 void diff_print_index(const char *zFile, int diffFlags){
43 if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
44 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
45 diff_printf("%s", z);
46 fossil_free(z);
47 }
48 }
49
50 /*
@@ -61,11 +46,11 @@
61 z = mprintf("%.*c %.*s %.*c\n",
62 x/2, '=', n1, zLeft, (x+1)/2, '=');
63 }else{
64 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
65 }
66 diff_printf("%s", z);
67 fossil_free(z);
68 }
69
70 /*
71 ** Show the difference between two files, one in memory and one on disk.
@@ -104,11 +89,11 @@
104 /* Compute and output the differences */
105 blob_zero(&out);
106 text_diff(pFile1, &file2, &out, diffFlags);
107 if( blob_size(&out) ){
108 diff_print_filenames(zName, zName2, diffFlags);
109 diff_printf("%s\n", blob_str(&out));
110 }
111
112 /* Release memory resources */
113 blob_reset(&file2);
114 blob_reset(&out);
@@ -163,11 +148,11 @@
163 Blob out; /* Diff output text */
164
165 blob_zero(&out);
166 text_diff(pFile1, pFile2, &out, diffFlags);
167 diff_print_filenames(zName, zName, diffFlags);
168 diff_printf("%s\n", blob_str(&out));
169
170 /* Release memory resources */
171 blob_reset(&out);
172 }else{
173 Blob cmd;
@@ -211,11 +196,12 @@
211 Blob content;
212 int isLink;
213 file_tree_name(zFileTreeName, &fname, 1);
214 historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
215 if( !isLink != !file_wd_islink(zFrom) ){
216 diff_printf("cannot compute difference between symlink and regular file\n");
 
217 }else{
218 diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, diffFlags);
219 }
220 blob_reset(&content);
221 blob_reset(&fname);
@@ -287,30 +273,31 @@
287 int isLink = db_column_int(&q, 5);
288 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
289 char *zToFree = zFullName;
290 int showDiff = 1;
291 if( isDeleted ){
292 diff_printf("DELETED %s\n", zPathname);
293 if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
294 }else if( file_access(zFullName, 0) ){
295 diff_printf("MISSING %s\n", zPathname);
296 if( !asNewFile ){ showDiff = 0; }
297 }else if( isNew ){
298 diff_printf("ADDED %s\n", zPathname);
299 srcid = 0;
300 if( !asNewFile ){ showDiff = 0; }
301 }else if( isChnged==3 ){
302 diff_printf("ADDED_BY_MERGE %s\n", zPathname);
303 srcid = 0;
304 if( !asNewFile ){ showDiff = 0; }
305 }
306 if( showDiff ){
307 Blob content;
308 if( !isLink != !file_wd_islink(zFullName) ){
309 diff_print_index(zPathname, diffFlags);
310 diff_print_filenames(zPathname, zPathname, diffFlags);
311 diff_printf("cannot compute difference between symlink and regular file\n");
 
312 continue;
313 }
314 if( srcid>0 ){
315 content_get(srcid, &content);
316 }else{
@@ -345,11 +332,12 @@
345 zName = blob_str(&fname);
346 historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
347 historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
348 if( isLink1 != isLink2 ){
349 diff_print_filenames(zName, zName, diffFlags);
350 diff_printf("cannot compute difference between symlink and regular file\n");
 
351 }else{
352 diff_file_mem(&v1, &v2, zName, zDiffCmd, diffFlags);
353 }
354 blob_reset(&v1);
355 blob_reset(&v2);
@@ -415,27 +403,27 @@
415 cmp = -1;
416 }else{
417 cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
418 }
419 if( cmp<0 ){
420 diff_printf("DELETED %s\n", pFromFile->zName);
421 if( asNewFlag ){
422 diff_manifest_entry(pFromFile, 0, zDiffCmd, diffFlags);
423 }
424 pFromFile = manifest_file_next(pFrom,0);
425 }else if( cmp>0 ){
426 diff_printf("ADDED %s\n", pToFile->zName);
427 if( asNewFlag ){
428 diff_manifest_entry(0, pToFile, zDiffCmd, diffFlags);
429 }
430 pToFile = manifest_file_next(pTo,0);
431 }else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
432 /* No changes */
433 pFromFile = manifest_file_next(pFrom,0);
434 pToFile = manifest_file_next(pTo,0);
435 }else{
436 /* diff_printf("CHANGED %s\n", pFromFile->zName); */
437 diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
438 pFromFile = manifest_file_next(pFrom,0);
439 pToFile = manifest_file_next(pTo,0);
440 }
441 }
442
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -19,32 +19,17 @@
19 */
20 #include "config.h"
21 #include "diffcmd.h"
22 #include <assert.h>
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24 /*
25 ** Print the "Index:" message that patches wants to see at the top of a diff.
26 */
27 void diff_print_index(const char *zFile, int diffFlags){
28 if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
29 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
30 fossil_print("%s", z);
31 fossil_free(z);
32 }
33 }
34
35 /*
@@ -61,11 +46,11 @@
46 z = mprintf("%.*c %.*s %.*c\n",
47 x/2, '=', n1, zLeft, (x+1)/2, '=');
48 }else{
49 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
50 }
51 fossil_print("%s", z);
52 fossil_free(z);
53 }
54
55 /*
56 ** Show the difference between two files, one in memory and one on disk.
@@ -104,11 +89,11 @@
89 /* Compute and output the differences */
90 blob_zero(&out);
91 text_diff(pFile1, &file2, &out, diffFlags);
92 if( blob_size(&out) ){
93 diff_print_filenames(zName, zName2, diffFlags);
94 fossil_print("%s\n", blob_str(&out));
95 }
96
97 /* Release memory resources */
98 blob_reset(&file2);
99 blob_reset(&out);
@@ -163,11 +148,11 @@
148 Blob out; /* Diff output text */
149
150 blob_zero(&out);
151 text_diff(pFile1, pFile2, &out, diffFlags);
152 diff_print_filenames(zName, zName, diffFlags);
153 fossil_print("%s\n", blob_str(&out));
154
155 /* Release memory resources */
156 blob_reset(&out);
157 }else{
158 Blob cmd;
@@ -211,11 +196,12 @@
196 Blob content;
197 int isLink;
198 file_tree_name(zFileTreeName, &fname, 1);
199 historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
200 if( !isLink != !file_wd_islink(zFrom) ){
201 fossil_print("cannot compute difference between "
202 "symlink and regular file\n");
203 }else{
204 diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, diffFlags);
205 }
206 blob_reset(&content);
207 blob_reset(&fname);
@@ -287,30 +273,31 @@
273 int isLink = db_column_int(&q, 5);
274 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
275 char *zToFree = zFullName;
276 int showDiff = 1;
277 if( isDeleted ){
278 fossil_print("DELETED %s\n", zPathname);
279 if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
280 }else if( file_access(zFullName, 0) ){
281 fossil_print("MISSING %s\n", zPathname);
282 if( !asNewFile ){ showDiff = 0; }
283 }else if( isNew ){
284 fossil_print("ADDED %s\n", zPathname);
285 srcid = 0;
286 if( !asNewFile ){ showDiff = 0; }
287 }else if( isChnged==3 ){
288 fossil_print("ADDED_BY_MERGE %s\n", zPathname);
289 srcid = 0;
290 if( !asNewFile ){ showDiff = 0; }
291 }
292 if( showDiff ){
293 Blob content;
294 if( !isLink != !file_wd_islink(zFullName) ){
295 diff_print_index(zPathname, diffFlags);
296 diff_print_filenames(zPathname, zPathname, diffFlags);
297 fossil_print("cannot compute difference between "
298 "symlink and regular file\n");
299 continue;
300 }
301 if( srcid>0 ){
302 content_get(srcid, &content);
303 }else{
@@ -345,11 +332,12 @@
332 zName = blob_str(&fname);
333 historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
334 historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
335 if( isLink1 != isLink2 ){
336 diff_print_filenames(zName, zName, diffFlags);
337 fossil_print("cannot compute difference "
338 " between symlink and regular file\n");
339 }else{
340 diff_file_mem(&v1, &v2, zName, zDiffCmd, diffFlags);
341 }
342 blob_reset(&v1);
343 blob_reset(&v2);
@@ -415,27 +403,27 @@
403 cmp = -1;
404 }else{
405 cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
406 }
407 if( cmp<0 ){
408 fossil_print("DELETED %s\n", pFromFile->zName);
409 if( asNewFlag ){
410 diff_manifest_entry(pFromFile, 0, zDiffCmd, diffFlags);
411 }
412 pFromFile = manifest_file_next(pFrom,0);
413 }else if( cmp>0 ){
414 fossil_print("ADDED %s\n", pToFile->zName);
415 if( asNewFlag ){
416 diff_manifest_entry(0, pToFile, zDiffCmd, diffFlags);
417 }
418 pToFile = manifest_file_next(pTo,0);
419 }else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
420 /* No changes */
421 pFromFile = manifest_file_next(pFrom,0);
422 pToFile = manifest_file_next(pTo,0);
423 }else{
424 /* fossil_print("CHANGED %s\n", pFromFile->zName); */
425 diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
426 pFromFile = manifest_file_next(pFrom,0);
427 pToFile = manifest_file_next(pTo,0);
428 }
429 }
430
--- src/printf.c
+++ src/printf.c
@@ -822,10 +822,11 @@
822822
fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
823823
free(zToFree);
824824
#else
825825
fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
826826
#endif
827
+ fflush(toStdErr ? stderr : stdout);
827828
}
828829
829830
/*
830831
** Write output for user consumption. If g.cgiOutput is enabled, then
831832
** send the output as part of the CGI reply. If g.cgiOutput is false,
832833
--- src/printf.c
+++ src/printf.c
@@ -822,10 +822,11 @@
822 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
823 free(zToFree);
824 #else
825 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
826 #endif
 
827 }
828
829 /*
830 ** Write output for user consumption. If g.cgiOutput is enabled, then
831 ** send the output as part of the CGI reply. If g.cgiOutput is false,
832
--- src/printf.c
+++ src/printf.c
@@ -822,10 +822,11 @@
822 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
823 free(zToFree);
824 #else
825 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
826 #endif
827 fflush(toStdErr ? stderr : stdout);
828 }
829
830 /*
831 ** Write output for user consumption. If g.cgiOutput is enabled, then
832 ** send the output as part of the CGI reply. If g.cgiOutput is false,
833

Keyboard Shortcuts

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