Fossil SCM

The command-line "diff" does not elide whitespace at the end of lines and it generates a well-formed patch file that can be feed directly into "patch -p 0". Ticket [a9f7b23c2e376af]. GUI diffs and the merge commands ignore end-of-line whitespace.

drh 2010-08-21 04:06 trunk
Commit 5ef7435ac0727637943710ecbbdc81e8e82e5c87
+13 -9
--- src/diff.c
+++ src/diff.c
@@ -72,11 +72,11 @@
7272
** confused by the diff output. Ticket [a9f7b23c2e376af5b0e5b]
7373
**
7474
** Return 0 if the file is binary or contains a line that is
7575
** too long.
7676
*/
77
-static DLine *break_into_lines(const char *z, int n, int *pnLine){
77
+static DLine *break_into_lines(const char *z, int n, int *pnLine, int ignoreWS){
7878
int nLine, i, j, k, x;
7979
unsigned int h, h2;
8080
DLine *a;
8181
8282
/* Count the number of lines. Allocate space to hold
@@ -104,11 +104,12 @@
104104
105105
/* Fill in the array */
106106
for(i=0; i<nLine; i++){
107107
a[i].z = z;
108108
for(j=0; z[j] && z[j]!='\n'; j++){}
109
- for(k=j; k>0 && isspace(z[k-1]); k--){break;}
109
+ k = j;
110
+ while( ignoreWS && k>0 && isspace(z[k-1]) ){ k--; }
110111
for(h=0, x=0; x<k; x++){
111112
h = h ^ (h<<2) ^ z[x];
112113
}
113114
a[i].h = h = (h<<LENGTH_MASK_SZ) | k;;
114115
h2 = h % nLine;
@@ -474,18 +475,21 @@
474475
*/
475476
int *text_diff(
476477
Blob *pA_Blob, /* FROM file */
477478
Blob *pB_Blob, /* TO file */
478479
Blob *pOut, /* Write unified diff here if not NULL */
479
- int nContext /* Amount of context to unified diff */
480
+ int nContext, /* Amount of context to unified diff */
481
+ int ignoreEolWs /* Ignore whitespace at the end of lines */
480482
){
481483
DContext c;
482484
483485
/* Prepare the input files */
484486
memset(&c, 0, sizeof(c));
485
- c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob), &c.nFrom);
486
- c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob), &c.nTo);
487
+ c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
488
+ &c.nFrom, ignoreEolWs);
489
+ c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
490
+ &c.nTo, ignoreEolWs);
487491
if( c.aFrom==0 || c.aTo==0 ){
488492
free(c.aFrom);
489493
free(c.aTo);
490494
if( pOut ){
491495
blob_appendf(pOut, "cannot compute difference between binary files\n");
@@ -524,11 +528,11 @@
524528
if( g.argc<4 ) usage("FILE1 FILE2 ...");
525529
blob_read_from_file(&a, g.argv[2]);
526530
for(i=3; i<g.argc; i++){
527531
if( i>3 ) printf("-------------------------------\n");
528532
blob_read_from_file(&b, g.argv[i]);
529
- R = text_diff(&a, &b, 0, 0);
533
+ R = text_diff(&a, &b, 0, 0, 0);
530534
for(r=0; R[r] || R[r+1] || R[r+2]; r += 3){
531535
printf(" copy %4d delete %4d insert %4d\n", R[r], R[r+1], R[r+2]);
532536
}
533537
/* free(R); */
534538
blob_reset(&b);
@@ -542,11 +546,11 @@
542546
Blob a, b, out;
543547
if( g.argc!=4 ) usage("FILE1 FILE2");
544548
blob_read_from_file(&a, g.argv[2]);
545549
blob_read_from_file(&b, g.argv[3]);
546550
blob_zero(&out);
547
- text_diff(&a, &b, &out, 3);
551
+ text_diff(&a, &b, &out, 3, 0);
548552
blob_write_to_file(&out, "-");
549553
}
550554
551555
/**************************************************************************
552556
** The basic difference engine is above. What follows is the annotation
@@ -576,11 +580,11 @@
576580
*/
577581
static int annotation_start(Annotator *p, Blob *pInput){
578582
int i;
579583
580584
memset(p, 0, sizeof(*p));
581
- p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput), &p->c.nTo);
585
+ p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,1);
582586
if( p->c.aTo==0 ){
583587
return 1;
584588
}
585589
p->aOrig = malloc( sizeof(p->aOrig[0])*p->c.nTo );
586590
if( p->aOrig==0 ) fossil_panic("out of memory");
@@ -604,11 +608,11 @@
604608
int i, j;
605609
int lnTo;
606610
607611
/* Prepare the parent file to be diffed */
608612
p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
609
- &p->c.nFrom);
613
+ &p->c.nFrom, 1);
610614
if( p->c.aFrom==0 ){
611615
return 1;
612616
}
613617
614618
/* Compute the differences going from pParent to the file being
615619
--- src/diff.c
+++ src/diff.c
@@ -72,11 +72,11 @@
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){
78 int nLine, i, j, k, x;
79 unsigned int h, h2;
80 DLine *a;
81
82 /* Count the number of lines. Allocate space to hold
@@ -104,11 +104,12 @@
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;
@@ -474,18 +475,21 @@
474 */
475 int *text_diff(
476 Blob *pA_Blob, /* FROM file */
477 Blob *pB_Blob, /* TO file */
478 Blob *pOut, /* Write unified diff here if not NULL */
479 int nContext /* Amount of context to unified diff */
 
480 ){
481 DContext c;
482
483 /* Prepare the input files */
484 memset(&c, 0, sizeof(c));
485 c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob), &c.nFrom);
486 c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob), &c.nTo);
 
 
487 if( c.aFrom==0 || c.aTo==0 ){
488 free(c.aFrom);
489 free(c.aTo);
490 if( pOut ){
491 blob_appendf(pOut, "cannot compute difference between binary files\n");
@@ -524,11 +528,11 @@
524 if( g.argc<4 ) usage("FILE1 FILE2 ...");
525 blob_read_from_file(&a, g.argv[2]);
526 for(i=3; i<g.argc; i++){
527 if( i>3 ) printf("-------------------------------\n");
528 blob_read_from_file(&b, g.argv[i]);
529 R = text_diff(&a, &b, 0, 0);
530 for(r=0; R[r] || R[r+1] || R[r+2]; r += 3){
531 printf(" copy %4d delete %4d insert %4d\n", R[r], R[r+1], R[r+2]);
532 }
533 /* free(R); */
534 blob_reset(&b);
@@ -542,11 +546,11 @@
542 Blob a, b, out;
543 if( g.argc!=4 ) usage("FILE1 FILE2");
544 blob_read_from_file(&a, g.argv[2]);
545 blob_read_from_file(&b, g.argv[3]);
546 blob_zero(&out);
547 text_diff(&a, &b, &out, 3);
548 blob_write_to_file(&out, "-");
549 }
550
551 /**************************************************************************
552 ** The basic difference engine is above. What follows is the annotation
@@ -576,11 +580,11 @@
576 */
577 static int annotation_start(Annotator *p, Blob *pInput){
578 int i;
579
580 memset(p, 0, sizeof(*p));
581 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput), &p->c.nTo);
582 if( p->c.aTo==0 ){
583 return 1;
584 }
585 p->aOrig = malloc( sizeof(p->aOrig[0])*p->c.nTo );
586 if( p->aOrig==0 ) fossil_panic("out of memory");
@@ -604,11 +608,11 @@
604 int i, j;
605 int lnTo;
606
607 /* Prepare the parent file to be diffed */
608 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
609 &p->c.nFrom);
610 if( p->c.aFrom==0 ){
611 return 1;
612 }
613
614 /* Compute the differences going from pParent to the file being
615
--- src/diff.c
+++ src/diff.c
@@ -72,11 +72,11 @@
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, int ignoreWS){
78 int nLine, i, j, k, x;
79 unsigned int h, h2;
80 DLine *a;
81
82 /* Count the number of lines. Allocate space to hold
@@ -104,11 +104,12 @@
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 k = j;
110 while( ignoreWS && k>0 && isspace(z[k-1]) ){ k--; }
111 for(h=0, x=0; x<k; x++){
112 h = h ^ (h<<2) ^ z[x];
113 }
114 a[i].h = h = (h<<LENGTH_MASK_SZ) | k;;
115 h2 = h % nLine;
@@ -474,18 +475,21 @@
475 */
476 int *text_diff(
477 Blob *pA_Blob, /* FROM file */
478 Blob *pB_Blob, /* TO file */
479 Blob *pOut, /* Write unified diff here if not NULL */
480 int nContext, /* Amount of context to unified diff */
481 int ignoreEolWs /* Ignore whitespace at the end of lines */
482 ){
483 DContext c;
484
485 /* Prepare the input files */
486 memset(&c, 0, sizeof(c));
487 c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
488 &c.nFrom, ignoreEolWs);
489 c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
490 &c.nTo, ignoreEolWs);
491 if( c.aFrom==0 || c.aTo==0 ){
492 free(c.aFrom);
493 free(c.aTo);
494 if( pOut ){
495 blob_appendf(pOut, "cannot compute difference between binary files\n");
@@ -524,11 +528,11 @@
528 if( g.argc<4 ) usage("FILE1 FILE2 ...");
529 blob_read_from_file(&a, g.argv[2]);
530 for(i=3; i<g.argc; i++){
531 if( i>3 ) printf("-------------------------------\n");
532 blob_read_from_file(&b, g.argv[i]);
533 R = text_diff(&a, &b, 0, 0, 0);
534 for(r=0; R[r] || R[r+1] || R[r+2]; r += 3){
535 printf(" copy %4d delete %4d insert %4d\n", R[r], R[r+1], R[r+2]);
536 }
537 /* free(R); */
538 blob_reset(&b);
@@ -542,11 +546,11 @@
546 Blob a, b, out;
547 if( g.argc!=4 ) usage("FILE1 FILE2");
548 blob_read_from_file(&a, g.argv[2]);
549 blob_read_from_file(&b, g.argv[3]);
550 blob_zero(&out);
551 text_diff(&a, &b, &out, 3, 0);
552 blob_write_to_file(&out, "-");
553 }
554
555 /**************************************************************************
556 ** The basic difference engine is above. What follows is the annotation
@@ -576,11 +580,11 @@
580 */
581 static int annotation_start(Annotator *p, Blob *pInput){
582 int i;
583
584 memset(p, 0, sizeof(*p));
585 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,1);
586 if( p->c.aTo==0 ){
587 return 1;
588 }
589 p->aOrig = malloc( sizeof(p->aOrig[0])*p->c.nTo );
590 if( p->aOrig==0 ) fossil_panic("out of memory");
@@ -604,11 +608,11 @@
608 int i, j;
609 int lnTo;
610
611 /* Prepare the parent file to be diffed */
612 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
613 &p->c.nFrom, 1);
614 if( p->c.aFrom==0 ){
615 return 1;
616 }
617
618 /* Compute the differences going from pParent to the file being
619
+33 -17
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -73,11 +73,12 @@
7373
*/
7474
static void diff_file(
7575
Blob *pFile1, /* In memory content to compare from */
7676
const char *zFile2, /* On disk content to compare to */
7777
const char *zName, /* Display name of the file */
78
- const char *zDiffCmd /* Command for comparison */
78
+ const char *zDiffCmd, /* Command for comparison */
79
+ int ignoreEolWs /* Ignore whitespace at end of lines */
7980
){
8081
if( zDiffCmd==0 ){
8182
Blob out; /* Diff output text */
8283
Blob file2; /* Content of zFile2 */
8384
@@ -85,11 +86,11 @@
8586
blob_zero(&file2);
8687
blob_read_from_file(&file2, zFile2);
8788
8889
/* Compute and output the differences */
8990
blob_zero(&out);
90
- text_diff(pFile1, &file2, &out, 5);
91
+ text_diff(pFile1, &file2, &out, 5, ignoreEolWs);
9192
printf("--- %s\n+++ %s\n", zName, zName);
9293
printf("%s\n", blob_str(&out));
9394
9495
/* Release memory resources */
9596
blob_reset(&file2);
@@ -136,17 +137,18 @@
136137
*/
137138
static void diff_file_mem(
138139
Blob *pFile1, /* In memory content to compare from */
139140
Blob *pFile2, /* In memory content to compare to */
140141
const char *zName, /* Display name of the file */
141
- const char *zDiffCmd /* Command for comparison */
142
+ const char *zDiffCmd, /* Command for comparison */
143
+ int ignoreEolWs /* Ignore whitespace at end of lines */
142144
){
143145
if( zDiffCmd==0 ){
144146
Blob out; /* Diff output text */
145147
146148
blob_zero(&out);
147
- text_diff(pFile1, pFile2, &out, 5);
149
+ text_diff(pFile1, pFile2, &out, 5, ignoreEolWs);
148150
printf("--- %s\n+++ %s\n", zName, zName);
149151
printf("%s\n", blob_str(&out));
150152
151153
/* Release memory resources */
152154
blob_reset(&out);
@@ -180,26 +182,34 @@
180182
181183
/*
182184
** Do a diff against a single file named in g.argv[2] from version zFrom
183185
** against the same file on disk.
184186
*/
185
-static void diff_one_against_disk(const char *zFrom, const char *zDiffCmd){
187
+static void diff_one_against_disk(
188
+ const char *zFrom, /* Name of file */
189
+ const char *zDiffCmd, /* Use this "diff" command */
190
+ int ignoreEolWs /* Ignore whitespace changes at end of lines */
191
+){
186192
Blob fname;
187193
Blob content;
188194
file_tree_name(g.argv[2], &fname, 1);
189195
historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
190
- diff_file(&content, g.argv[2], g.argv[2], zDiffCmd);
196
+ diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
191197
blob_reset(&content);
192198
blob_reset(&fname);
193199
}
194200
195201
/*
196202
** Run a diff between the version zFrom and files on disk. zFrom might
197203
** be NULL which means to simply show the difference between the edited
198204
** files on disk and the check-out on which they are based.
199205
*/
200
-static void diff_all_against_disk(const char *zFrom, const char *zDiffCmd){
206
+static void diff_all_against_disk(
207
+ const char *zFrom, /* Version to difference from */
208
+ const char *zDiffCmd, /* Use this diff command. NULL for built-in */
209
+ int ignoreEolWs /* Ignore end-of-line whitespace */
210
+){
201211
int vid;
202212
Blob sql;
203213
Stmt q;
204214
205215
vid = db_lget_int("checkout", 0);
@@ -265,11 +275,11 @@
265275
content_get(srcid, &content);
266276
printf("Index: %s\n======================================="
267277
"============================\n",
268278
zPathname
269279
);
270
- diff_file(&content, zFullName, zPathname, zDiffCmd);
280
+ diff_file(&content, zFullName, zPathname, zDiffCmd, ignoreEolWs);
271281
blob_reset(&content);
272282
}
273283
free(zFullName);
274284
}
275285
db_finalize(&q);
@@ -282,20 +292,21 @@
282292
** The filename is contained in g.argv[2].
283293
*/
284294
static void diff_one_two_versions(
285295
const char *zFrom,
286296
const char *zTo,
287
- const char *zDiffCmd
297
+ const char *zDiffCmd,
298
+ int ignoreEolWs
288299
){
289300
char *zName;
290301
Blob fname;
291302
Blob v1, v2;
292303
file_tree_name(g.argv[2], &fname, 1);
293304
zName = blob_str(&fname);
294305
historical_version_of_file(zFrom, zName, &v1, 0);
295306
historical_version_of_file(zTo, zName, &v2, 0);
296
- diff_file_mem(&v1, &v2, zName, zDiffCmd);
307
+ diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
297308
blob_reset(&v1);
298309
blob_reset(&v2);
299310
blob_reset(&fname);
300311
}
301312
@@ -303,11 +314,12 @@
303314
** Output the differences between two check-ins.
304315
*/
305316
static void diff_all_two_versions(
306317
const char *zFrom,
307318
const char *zTo,
308
- const char *zDiffCmd
319
+ const char *zDiffCmd,
320
+ int ignoreEolWs
309321
){
310322
Manifest mFrom, mTo;
311323
int iFrom, iTo;
312324
313325
manifest_from_name(zFrom, &mFrom);
@@ -334,15 +346,19 @@
334346
iTo++;
335347
}else{
336348
Blob f1, f2;
337349
int rid;
338350
printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
351
+ printf("Index: %s\n======================================="
352
+ "============================\n",
353
+ mFrom.aFile[iFrom].zName
354
+ );
339355
rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
340356
content_get(rid, &f1);
341357
rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
342358
content_get(rid, &f2);
343
- diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd);
359
+ diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd, ignoreEolWs);
344360
blob_reset(&f1);
345361
blob_reset(&f2);
346362
iFrom++;
347363
iTo++;
348364
}
@@ -393,24 +409,24 @@
393409
verify_all_options();
394410
if( !isInternDiff && g.argc==3 ){
395411
zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
396412
}
397413
if( g.argc==3 ){
398
- diff_one_against_disk(zFrom, zDiffCmd);
414
+ diff_one_against_disk(zFrom, zDiffCmd, 0);
399415
}else{
400
- diff_all_against_disk(zFrom, zDiffCmd);
416
+ diff_all_against_disk(zFrom, zDiffCmd, 0);
401417
}
402418
}else if( zFrom==0 ){
403419
fossil_fatal("must use --from if --to is present");
404420
}else{
405421
db_find_and_open_repository(1);
406422
verify_all_options();
407
- if( !isInternDiff && g.argc==3 ){
423
+ if( !isInternDiff ){
408424
zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
409425
}
410426
if( g.argc==3 ){
411
- diff_one_two_versions(zFrom, zTo, zDiffCmd);
427
+ diff_one_two_versions(zFrom, zTo, zDiffCmd, 0);
412428
}else{
413
- diff_all_two_versions(zFrom, zTo, zDiffCmd);
429
+ diff_all_two_versions(zFrom, zTo, zDiffCmd, 0);
414430
}
415431
}
416432
}
417433
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -73,11 +73,12 @@
73 */
74 static void diff_file(
75 Blob *pFile1, /* In memory content to compare from */
76 const char *zFile2, /* On disk content to compare to */
77 const char *zName, /* Display name of the file */
78 const char *zDiffCmd /* Command for comparison */
 
79 ){
80 if( zDiffCmd==0 ){
81 Blob out; /* Diff output text */
82 Blob file2; /* Content of zFile2 */
83
@@ -85,11 +86,11 @@
85 blob_zero(&file2);
86 blob_read_from_file(&file2, zFile2);
87
88 /* Compute and output the differences */
89 blob_zero(&out);
90 text_diff(pFile1, &file2, &out, 5);
91 printf("--- %s\n+++ %s\n", zName, zName);
92 printf("%s\n", blob_str(&out));
93
94 /* Release memory resources */
95 blob_reset(&file2);
@@ -136,17 +137,18 @@
136 */
137 static void diff_file_mem(
138 Blob *pFile1, /* In memory content to compare from */
139 Blob *pFile2, /* In memory content to compare to */
140 const char *zName, /* Display name of the file */
141 const char *zDiffCmd /* Command for comparison */
 
142 ){
143 if( zDiffCmd==0 ){
144 Blob out; /* Diff output text */
145
146 blob_zero(&out);
147 text_diff(pFile1, pFile2, &out, 5);
148 printf("--- %s\n+++ %s\n", zName, zName);
149 printf("%s\n", blob_str(&out));
150
151 /* Release memory resources */
152 blob_reset(&out);
@@ -180,26 +182,34 @@
180
181 /*
182 ** Do a diff against a single file named in g.argv[2] from version zFrom
183 ** against the same file on disk.
184 */
185 static void diff_one_against_disk(const char *zFrom, const char *zDiffCmd){
 
 
 
 
186 Blob fname;
187 Blob content;
188 file_tree_name(g.argv[2], &fname, 1);
189 historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
190 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd);
191 blob_reset(&content);
192 blob_reset(&fname);
193 }
194
195 /*
196 ** Run a diff between the version zFrom and files on disk. zFrom might
197 ** be NULL which means to simply show the difference between the edited
198 ** files on disk and the check-out on which they are based.
199 */
200 static void diff_all_against_disk(const char *zFrom, const char *zDiffCmd){
 
 
 
 
201 int vid;
202 Blob sql;
203 Stmt q;
204
205 vid = db_lget_int("checkout", 0);
@@ -265,11 +275,11 @@
265 content_get(srcid, &content);
266 printf("Index: %s\n======================================="
267 "============================\n",
268 zPathname
269 );
270 diff_file(&content, zFullName, zPathname, zDiffCmd);
271 blob_reset(&content);
272 }
273 free(zFullName);
274 }
275 db_finalize(&q);
@@ -282,20 +292,21 @@
282 ** The filename is contained in g.argv[2].
283 */
284 static void diff_one_two_versions(
285 const char *zFrom,
286 const char *zTo,
287 const char *zDiffCmd
 
288 ){
289 char *zName;
290 Blob fname;
291 Blob v1, v2;
292 file_tree_name(g.argv[2], &fname, 1);
293 zName = blob_str(&fname);
294 historical_version_of_file(zFrom, zName, &v1, 0);
295 historical_version_of_file(zTo, zName, &v2, 0);
296 diff_file_mem(&v1, &v2, zName, zDiffCmd);
297 blob_reset(&v1);
298 blob_reset(&v2);
299 blob_reset(&fname);
300 }
301
@@ -303,11 +314,12 @@
303 ** Output the differences between two check-ins.
304 */
305 static void diff_all_two_versions(
306 const char *zFrom,
307 const char *zTo,
308 const char *zDiffCmd
 
309 ){
310 Manifest mFrom, mTo;
311 int iFrom, iTo;
312
313 manifest_from_name(zFrom, &mFrom);
@@ -334,15 +346,19 @@
334 iTo++;
335 }else{
336 Blob f1, f2;
337 int rid;
338 printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
 
 
 
 
339 rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
340 content_get(rid, &f1);
341 rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
342 content_get(rid, &f2);
343 diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd);
344 blob_reset(&f1);
345 blob_reset(&f2);
346 iFrom++;
347 iTo++;
348 }
@@ -393,24 +409,24 @@
393 verify_all_options();
394 if( !isInternDiff && g.argc==3 ){
395 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
396 }
397 if( g.argc==3 ){
398 diff_one_against_disk(zFrom, zDiffCmd);
399 }else{
400 diff_all_against_disk(zFrom, zDiffCmd);
401 }
402 }else if( zFrom==0 ){
403 fossil_fatal("must use --from if --to is present");
404 }else{
405 db_find_and_open_repository(1);
406 verify_all_options();
407 if( !isInternDiff && g.argc==3 ){
408 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
409 }
410 if( g.argc==3 ){
411 diff_one_two_versions(zFrom, zTo, zDiffCmd);
412 }else{
413 diff_all_two_versions(zFrom, zTo, zDiffCmd);
414 }
415 }
416 }
417
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -73,11 +73,12 @@
73 */
74 static void diff_file(
75 Blob *pFile1, /* In memory content to compare from */
76 const char *zFile2, /* On disk content to compare to */
77 const char *zName, /* Display name of the file */
78 const char *zDiffCmd, /* Command for comparison */
79 int ignoreEolWs /* Ignore whitespace at end of lines */
80 ){
81 if( zDiffCmd==0 ){
82 Blob out; /* Diff output text */
83 Blob file2; /* Content of zFile2 */
84
@@ -85,11 +86,11 @@
86 blob_zero(&file2);
87 blob_read_from_file(&file2, zFile2);
88
89 /* Compute and output the differences */
90 blob_zero(&out);
91 text_diff(pFile1, &file2, &out, 5, ignoreEolWs);
92 printf("--- %s\n+++ %s\n", zName, zName);
93 printf("%s\n", blob_str(&out));
94
95 /* Release memory resources */
96 blob_reset(&file2);
@@ -136,17 +137,18 @@
137 */
138 static void diff_file_mem(
139 Blob *pFile1, /* In memory content to compare from */
140 Blob *pFile2, /* In memory content to compare to */
141 const char *zName, /* Display name of the file */
142 const char *zDiffCmd, /* Command for comparison */
143 int ignoreEolWs /* Ignore whitespace at end of lines */
144 ){
145 if( zDiffCmd==0 ){
146 Blob out; /* Diff output text */
147
148 blob_zero(&out);
149 text_diff(pFile1, pFile2, &out, 5, ignoreEolWs);
150 printf("--- %s\n+++ %s\n", zName, zName);
151 printf("%s\n", blob_str(&out));
152
153 /* Release memory resources */
154 blob_reset(&out);
@@ -180,26 +182,34 @@
182
183 /*
184 ** Do a diff against a single file named in g.argv[2] from version zFrom
185 ** against the same file on disk.
186 */
187 static void diff_one_against_disk(
188 const char *zFrom, /* Name of file */
189 const char *zDiffCmd, /* Use this "diff" command */
190 int ignoreEolWs /* Ignore whitespace changes at end of lines */
191 ){
192 Blob fname;
193 Blob content;
194 file_tree_name(g.argv[2], &fname, 1);
195 historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
196 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
197 blob_reset(&content);
198 blob_reset(&fname);
199 }
200
201 /*
202 ** Run a diff between the version zFrom and files on disk. zFrom might
203 ** be NULL which means to simply show the difference between the edited
204 ** files on disk and the check-out on which they are based.
205 */
206 static void diff_all_against_disk(
207 const char *zFrom, /* Version to difference from */
208 const char *zDiffCmd, /* Use this diff command. NULL for built-in */
209 int ignoreEolWs /* Ignore end-of-line whitespace */
210 ){
211 int vid;
212 Blob sql;
213 Stmt q;
214
215 vid = db_lget_int("checkout", 0);
@@ -265,11 +275,11 @@
275 content_get(srcid, &content);
276 printf("Index: %s\n======================================="
277 "============================\n",
278 zPathname
279 );
280 diff_file(&content, zFullName, zPathname, zDiffCmd, ignoreEolWs);
281 blob_reset(&content);
282 }
283 free(zFullName);
284 }
285 db_finalize(&q);
@@ -282,20 +292,21 @@
292 ** The filename is contained in g.argv[2].
293 */
294 static void diff_one_two_versions(
295 const char *zFrom,
296 const char *zTo,
297 const char *zDiffCmd,
298 int ignoreEolWs
299 ){
300 char *zName;
301 Blob fname;
302 Blob v1, v2;
303 file_tree_name(g.argv[2], &fname, 1);
304 zName = blob_str(&fname);
305 historical_version_of_file(zFrom, zName, &v1, 0);
306 historical_version_of_file(zTo, zName, &v2, 0);
307 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
308 blob_reset(&v1);
309 blob_reset(&v2);
310 blob_reset(&fname);
311 }
312
@@ -303,11 +314,12 @@
314 ** Output the differences between two check-ins.
315 */
316 static void diff_all_two_versions(
317 const char *zFrom,
318 const char *zTo,
319 const char *zDiffCmd,
320 int ignoreEolWs
321 ){
322 Manifest mFrom, mTo;
323 int iFrom, iTo;
324
325 manifest_from_name(zFrom, &mFrom);
@@ -334,15 +346,19 @@
346 iTo++;
347 }else{
348 Blob f1, f2;
349 int rid;
350 printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
351 printf("Index: %s\n======================================="
352 "============================\n",
353 mFrom.aFile[iFrom].zName
354 );
355 rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
356 content_get(rid, &f1);
357 rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
358 content_get(rid, &f2);
359 diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd, ignoreEolWs);
360 blob_reset(&f1);
361 blob_reset(&f2);
362 iFrom++;
363 iTo++;
364 }
@@ -393,24 +409,24 @@
409 verify_all_options();
410 if( !isInternDiff && g.argc==3 ){
411 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
412 }
413 if( g.argc==3 ){
414 diff_one_against_disk(zFrom, zDiffCmd, 0);
415 }else{
416 diff_all_against_disk(zFrom, zDiffCmd, 0);
417 }
418 }else if( zFrom==0 ){
419 fossil_fatal("must use --from if --to is present");
420 }else{
421 db_find_and_open_repository(1);
422 verify_all_options();
423 if( !isInternDiff ){
424 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
425 }
426 if( g.argc==3 ){
427 diff_one_two_versions(zFrom, zTo, zDiffCmd, 0);
428 }else{
429 diff_all_two_versions(zFrom, zTo, zDiffCmd, 0);
430 }
431 }
432 }
433
+2 -2
--- src/info.c
+++ src/info.c
@@ -238,11 +238,11 @@
238238
static void append_diff(int fromid, int toid){
239239
Blob from, to, out;
240240
content_get(fromid, &from);
241241
content_get(toid, &to);
242242
blob_zero(&out);
243
- text_diff(&from, &to, &out, 5);
243
+ text_diff(&from, &to, &out, 5, 1);
244244
@ %h(blob_str(&out))
245245
blob_reset(&from);
246246
blob_reset(&to);
247247
blob_reset(&out);
248248
}
@@ -883,11 +883,11 @@
883883
@ <hr>
884884
@ <blockquote><pre>
885885
content_get(v1, &c1);
886886
content_get(v2, &c2);
887887
blob_zero(&diff);
888
- text_diff(&c1, &c2, &diff, 4);
888
+ text_diff(&c1, &c2, &diff, 4, 1);
889889
blob_reset(&c1);
890890
blob_reset(&c2);
891891
@ %h(blob_str(&diff))
892892
@ </pre></blockquote>
893893
blob_reset(&diff);
894894
--- src/info.c
+++ src/info.c
@@ -238,11 +238,11 @@
238 static void append_diff(int fromid, int toid){
239 Blob from, to, out;
240 content_get(fromid, &from);
241 content_get(toid, &to);
242 blob_zero(&out);
243 text_diff(&from, &to, &out, 5);
244 @ %h(blob_str(&out))
245 blob_reset(&from);
246 blob_reset(&to);
247 blob_reset(&out);
248 }
@@ -883,11 +883,11 @@
883 @ <hr>
884 @ <blockquote><pre>
885 content_get(v1, &c1);
886 content_get(v2, &c2);
887 blob_zero(&diff);
888 text_diff(&c1, &c2, &diff, 4);
889 blob_reset(&c1);
890 blob_reset(&c2);
891 @ %h(blob_str(&diff))
892 @ </pre></blockquote>
893 blob_reset(&diff);
894
--- src/info.c
+++ src/info.c
@@ -238,11 +238,11 @@
238 static void append_diff(int fromid, int toid){
239 Blob from, to, out;
240 content_get(fromid, &from);
241 content_get(toid, &to);
242 blob_zero(&out);
243 text_diff(&from, &to, &out, 5, 1);
244 @ %h(blob_str(&out))
245 blob_reset(&from);
246 blob_reset(&to);
247 blob_reset(&out);
248 }
@@ -883,11 +883,11 @@
883 @ <hr>
884 @ <blockquote><pre>
885 content_get(v1, &c1);
886 content_get(v2, &c2);
887 blob_zero(&diff);
888 text_diff(&c1, &c2, &diff, 4, 1);
889 blob_reset(&c1);
890 blob_reset(&c2);
891 @ %h(blob_str(&diff))
892 @ </pre></blockquote>
893 blob_reset(&diff);
894
+2 -2
--- src/merge3.c
+++ src/merge3.c
@@ -165,12 +165,12 @@
165165
** is the number of lines of text to copy directly from the pivot,
166166
** the second integer is the number of lines of text to omit from the
167167
** pivot, and the third integer is the number of lines of text that are
168168
** inserted. The edit array ends with a triple of 0,0,0.
169169
*/
170
- aC1 = text_diff(pPivot, pV1, 0, 0);
171
- aC2 = text_diff(pPivot, pV2, 0, 0);
170
+ aC1 = text_diff(pPivot, pV1, 0, 0, 1);
171
+ aC2 = text_diff(pPivot, pV2, 0, 0, 1);
172172
if( aC1==0 || aC2==0 ){
173173
free(aC1);
174174
free(aC2);
175175
return -1;
176176
}
177177
--- src/merge3.c
+++ src/merge3.c
@@ -165,12 +165,12 @@
165 ** is the number of lines of text to copy directly from the pivot,
166 ** the second integer is the number of lines of text to omit from the
167 ** pivot, and the third integer is the number of lines of text that are
168 ** inserted. The edit array ends with a triple of 0,0,0.
169 */
170 aC1 = text_diff(pPivot, pV1, 0, 0);
171 aC2 = text_diff(pPivot, pV2, 0, 0);
172 if( aC1==0 || aC2==0 ){
173 free(aC1);
174 free(aC2);
175 return -1;
176 }
177
--- src/merge3.c
+++ src/merge3.c
@@ -165,12 +165,12 @@
165 ** is the number of lines of text to copy directly from the pivot,
166 ** the second integer is the number of lines of text to omit from the
167 ** pivot, and the third integer is the number of lines of text that are
168 ** inserted. The edit array ends with a triple of 0,0,0.
169 */
170 aC1 = text_diff(pPivot, pV1, 0, 0, 1);
171 aC2 = text_diff(pPivot, pV2, 0, 0, 1);
172 if( aC1==0 || aC2==0 ){
173 free(aC1);
174 free(aC2);
175 return -1;
176 }
177
+1 -1
--- src/wiki.c
+++ src/wiki.c
@@ -634,11 +634,11 @@
634634
if( m2.type==CFTYPE_WIKI ){
635635
blob_init(&w2, m2.zWiki, -1);
636636
}
637637
}
638638
blob_zero(&d);
639
- text_diff(&w2, &w1, &d, 5);
639
+ text_diff(&w2, &w1, &d, 5, 1);
640640
@ <pre>
641641
@ %h(blob_str(&d))
642642
@ </pre>
643643
style_footer();
644644
}
645645
--- src/wiki.c
+++ src/wiki.c
@@ -634,11 +634,11 @@
634 if( m2.type==CFTYPE_WIKI ){
635 blob_init(&w2, m2.zWiki, -1);
636 }
637 }
638 blob_zero(&d);
639 text_diff(&w2, &w1, &d, 5);
640 @ <pre>
641 @ %h(blob_str(&d))
642 @ </pre>
643 style_footer();
644 }
645
--- src/wiki.c
+++ src/wiki.c
@@ -634,11 +634,11 @@
634 if( m2.type==CFTYPE_WIKI ){
635 blob_init(&w2, m2.zWiki, -1);
636 }
637 }
638 blob_zero(&d);
639 text_diff(&w2, &w1, &d, 5, 1);
640 @ <pre>
641 @ %h(blob_str(&d))
642 @ </pre>
643 style_footer();
644 }
645

Keyboard Shortcuts

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