︙ | | |
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}else{
vprintf(zFormat, ap);
}
va_end(ap);
}
/*
** Print the "Index:" message that patch wants to see at the top of a diff.
** Print the "Index:" message that patches wants to see at the top of a diff.
*/
void diff_print_index(const char *zFile){
diff_printf("Index: %s\n======================================="
"============================\n", zFile);
void diff_print_index(const char *zFile, int diffFlags){
if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
diff_printf("%s", z);
fossil_free(z);
}
}
/*
** Print the +++/--- filename lines for a diff operation.
*/
void diff_print_filenames(const char *zLeft, const char *zRight, int diffFlags){
char *z = 0;
if( diffFlags & DIFF_SIDEBYSIDE ){
int w = diff_width(diffFlags);
int n1 = strlen(zLeft);
int x;
if( n1>w*2 ) n1 = w*2;
x = w*2+17 - (n1+2);
z = mprintf("%.*c %.*s %.*c\n",
x/2, '=', n1, zLeft, (x+1)/2, '=');
}else{
z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
}
diff_printf("%s", z);
fossil_free(z);
}
/*
** Show the difference between two files, one in memory and one on disk.
**
** The difference is the set of edits needed to transform pFile1 into
** zFile2. The content of pFile1 is in memory. zFile2 exists on disk.
|
︙ | | |
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
-
+
|
zName2 = zName;
}
/* Compute and output the differences */
blob_zero(&out);
text_diff(pFile1, &file2, &out, diffFlags);
if( blob_size(&out) ){
diff_printf("--- %s\n+++ %s\n", zName, zName2);
diff_print_filenames(zName, zName2, diffFlags);
diff_printf("%s\n", blob_str(&out));
}
/* Release memory resources */
blob_reset(&file2);
blob_reset(&out);
}else{
|
︙ | | |
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
-
+
|
int diffFlags /* Diff flags */
){
if( zDiffCmd==0 ){
Blob out; /* Diff output text */
blob_zero(&out);
text_diff(pFile1, pFile2, &out, diffFlags);
diff_printf("--- %s\n+++ %s\n", zName, zName);
diff_print_filenames(zName, zName, diffFlags);
diff_printf("%s\n", blob_str(&out));
/* Release memory resources */
blob_reset(&out);
}else{
Blob cmd;
char zTemp1[300];
|
︙ | | |
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
-
-
+
+
-
+
|
diff_printf("ADDED_BY_MERGE %s\n", zPathname);
srcid = 0;
if( !asNewFile ){ showDiff = 0; }
}
if( showDiff ){
Blob content;
if( !isLink != !file_wd_islink(zFullName) ){
diff_print_index(zPathname);
diff_printf("--- %s\n+++ %s\n", zPathname, zPathname);
diff_print_index(zPathname, diffFlags);
diff_print_filenames(zPathname, zPathname, diffFlags);
diff_printf("cannot compute difference between symlink and regular file\n");
continue;
}
if( srcid>0 ){
content_get(srcid, &content);
}else{
blob_zero(&content);
}
diff_print_index(zPathname);
diff_print_index(zPathname, diffFlags);
diff_file(&content, zFullName, zPathname, zDiffCmd, diffFlags);
blob_reset(&content);
}
free(zToFree);
}
db_finalize(&q);
db_end_transaction(1); /* ROLLBACK */
|
︙ | | |
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
-
+
|
Blob v1, v2;
int isLink1, isLink2;
file_tree_name(zFileTreeName, &fname, 1);
zName = blob_str(&fname);
historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
if( isLink1 != isLink2 ){
diff_printf("--- %s\n+++ %s\n", zName, zName);
diff_print_filenames(zName, zName, diffFlags);
diff_printf("cannot compute difference between symlink and regular file\n");
}else{
diff_file_mem(&v1, &v2, zName, zDiffCmd, diffFlags);
}
blob_reset(&v1);
blob_reset(&v2);
blob_reset(&fname);
|
︙ | | |
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
-
+
|
struct ManifestFile *pTo,
const char *zDiffCmd,
int diffFlags
){
Blob f1, f2;
int rid;
const char *zName = pFrom ? pFrom->zName : pTo->zName;
diff_print_index(zName);
diff_print_index(zName, diffFlags);
if( pFrom ){
rid = uuid_to_rid(pFrom->zUuid, 0);
content_get(rid, &f1);
}else{
blob_zero(&f1);
}
if( pTo ){
|
︙ | | |
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
-
+
|
int isGDiff; /* True for gdiff. False for normal diff */
int isInternDiff; /* True for internal diff */
int hasNFlag; /* True if -N or --new-file flag is used */
const char *zFrom; /* Source version number */
const char *zTo; /* Target version number */
const char *zDiffCmd = 0; /* External diff command. NULL for internal diff */
int diffFlags = 0; /* Flags to control the DIFF */
const char *z;
int f;
isGDiff = g.argv[1][0]=='g';
isInternDiff = find_option("internal","i",0)!=0;
zFrom = find_option("from", "r", 1);
zTo = find_option("to", 0, 1);
diffFlags = diff_options();
hasNFlag = find_option("new-file","N",0)!=0;
if( find_option("side-by-side","y",0)!=0 ) diffFlags |= DIFF_SIDEBYSIDE;
if( (z = find_option("context","c",1))!=0 && (f = atoi(z))>0 ){
if( f > DIFF_CONTEXT_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( hasNFlag ) diffFlags |= DIFF_NEWFILE;
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
f *= DIFF_CONTEXT_MASK+1;
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( hasNFlag ) diffFlags |= DIFF_NEWFILE;
if( zTo==0 ){
db_must_be_within_tree();
verify_all_options();
if( !isInternDiff ){
zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
}
if( g.argc>=3 ){
for(f=2; f<g.argc; ++f){
diff_one_against_disk(zFrom, zDiffCmd, 0, g.argv[f]);
diff_one_against_disk(zFrom, zDiffCmd, diffFlags, g.argv[f]);
}
}else{
diff_all_against_disk(zFrom, zDiffCmd, diffFlags);
}
}else if( zFrom==0 ){
fossil_fatal("must use --from if --to is present");
}else{
db_find_and_open_repository(0, 0);
verify_all_options();
if( !isInternDiff ){
zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
}
if( g.argc>=3 ){
for(f=2; f<g.argc; ++f){
diff_one_two_versions(zFrom, zTo, zDiffCmd, 0, g.argv[f]);
diff_one_two_versions(zFrom, zTo, zDiffCmd, diffFlags, g.argv[f]);
}
}else{
diff_all_two_versions(zFrom, zTo, zDiffCmd, diffFlags);
}
}
}
|
︙ | | |