Fossil SCM

Add the -v (and --verbose) option to the "fossil commit" command.

drh 2021-01-31 20:18 trunk merge
Commit 7ee98fea2d2809082cc813f5144a63414fbe2e592395a0cf6df7c37649e8d99d
--- src/checkin.c
+++ src/checkin.c
@@ -1237,10 +1237,15 @@
12371237
int i, n;
12381238
char *z;
12391239
n = blob_size(&line);
12401240
z = blob_buffer(&line);
12411241
for(i=0; i<n && fossil_isspace(z[i]); i++){}
1242
+ if( fossil_strncmp(
1243
+ "# NOTE: The below diff is not inserted into the commit message.\n",
1244
+ z, n)==0 ){
1245
+ break;
1246
+ }
12421247
if( i<n && z[i]=='#' ) continue;
12431248
if( i<n || blob_size(pComment)>0 ){
12441249
blob_appendf(pComment, "%b", &line);
12451250
}
12461251
}
@@ -1324,10 +1329,44 @@
13241329
blob_append(&prompt,
13251330
"#\n"
13261331
"# All merged-in branches will be closed due to the --integrate flag\n"
13271332
"#\n", -1
13281333
);
1334
+ }
1335
+ if( p->verboseFlag ){
1336
+ blob_append(&prompt,
1337
+ "#\n"
1338
+ "# NOTE: The below diff is not inserted into the commit message.\n\n",
1339
+ -1
1340
+ );
1341
+ if( g.aCommitFile ){
1342
+ FileDirList *diffFiles;
1343
+ int i;
1344
+ diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles));
1345
+ for( i=0; g.aCommitFile[i]!=0; ++i ){
1346
+ diffFiles[i].zName = db_text(0,
1347
+ "SELECT pathname FROM vfile WHERE id=%d", g.aCommitFile[i]);
1348
+ if( fossil_strcmp(diffFiles[i].zName, "." )==0 ){
1349
+ diffFiles[0].zName[0] = '.';
1350
+ diffFiles[0].zName[1] = 0;
1351
+ break;
1352
+ }
1353
+ diffFiles[i].nName = strlen(diffFiles[i].zName);
1354
+ diffFiles[i].nUsed = 0;
1355
+ }
1356
+ diff_against_disk(0, 0, diff_get_binary_glob(),
1357
+ db_get_boolean("diff-binary", 1),
1358
+ DIFF_VERBOSE, diffFiles, &prompt);
1359
+ for( i=0; diffFiles[i].zName; ++i ){
1360
+ fossil_free(diffFiles[i].zName);
1361
+ }
1362
+ fossil_free(diffFiles);
1363
+ }else{
1364
+ diff_against_disk(0, 0, diff_get_binary_glob(),
1365
+ db_get_boolean("diff-binary", 1),
1366
+ DIFF_VERBOSE, 0, &prompt);
1367
+ }
13291368
}
13301369
prompt_for_user_comment(pComment, &prompt);
13311370
blob_reset(&prompt);
13321371
}
13331372
@@ -1543,10 +1582,11 @@
15431582
Blob *pComment; /* Check-in comment text */
15441583
const char *zMimetype; /* Mimetype of check-in command. May be NULL */
15451584
int verifyDate; /* Verify that child is younger */
15461585
int closeFlag; /* Close the branch being committed */
15471586
int integrateFlag; /* Close merged-in branches */
1587
+ int verboseFlag; /* Show diff in editor for check-in comment */
15481588
Blob *pCksum; /* Repository checksum. May be 0 */
15491589
const char *zDateOvrd; /* Date override. If 0 then use 'now' */
15501590
const char *zUserOvrd; /* User override. If 0 then use login_name() */
15511591
const char *zBranch; /* Branch name. May be 0 */
15521592
const char *zColor; /* One-time background color. May be 0 */
@@ -2090,10 +2130,12 @@
20902130
** --integrate close all merged-in branches
20912131
** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment
20922132
** -M|--message-file FILE read the commit comment from given file
20932133
** --mimetype MIMETYPE mimetype of check-in comment
20942134
** -n|--dry-run If given, display instead of run actions
2135
+** -v|--verbose Display in the editor a unified diff of the
2136
+** changes to be committed with this check-in
20952137
** --no-prompt This option disables prompting the user for
20962138
** input and assumes an answer of 'No' for every
20972139
** question.
20982140
** --no-warnings omit all warnings about file contents
20992141
** --no-verify do not run before-commit hooks
@@ -2194,10 +2236,11 @@
21942236
sCiInfo.zColor = find_option("bgcolor",0,1);
21952237
sCiInfo.zBrClr = find_option("branchcolor",0,1);
21962238
sCiInfo.closeFlag = find_option("close",0,0)!=0;
21972239
sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
21982240
sCiInfo.zMimetype = find_option("mimetype",0,1);
2241
+ sCiInfo.verboseFlag = find_option("verbose", "v", 0)!=0;
21992242
while( (zTag = find_option("tag",0,1))!=0 ){
22002243
if( zTag[0]==0 ) continue;
22012244
sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
22022245
sizeof(char*)*(nTag+2));
22032246
sCiInfo.azTag[nTag++] = zTag;
22042247
--- src/checkin.c
+++ src/checkin.c
@@ -1237,10 +1237,15 @@
1237 int i, n;
1238 char *z;
1239 n = blob_size(&line);
1240 z = blob_buffer(&line);
1241 for(i=0; i<n && fossil_isspace(z[i]); i++){}
 
 
 
 
 
1242 if( i<n && z[i]=='#' ) continue;
1243 if( i<n || blob_size(pComment)>0 ){
1244 blob_appendf(pComment, "%b", &line);
1245 }
1246 }
@@ -1324,10 +1329,44 @@
1324 blob_append(&prompt,
1325 "#\n"
1326 "# All merged-in branches will be closed due to the --integrate flag\n"
1327 "#\n", -1
1328 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1329 }
1330 prompt_for_user_comment(pComment, &prompt);
1331 blob_reset(&prompt);
1332 }
1333
@@ -1543,10 +1582,11 @@
1543 Blob *pComment; /* Check-in comment text */
1544 const char *zMimetype; /* Mimetype of check-in command. May be NULL */
1545 int verifyDate; /* Verify that child is younger */
1546 int closeFlag; /* Close the branch being committed */
1547 int integrateFlag; /* Close merged-in branches */
 
1548 Blob *pCksum; /* Repository checksum. May be 0 */
1549 const char *zDateOvrd; /* Date override. If 0 then use 'now' */
1550 const char *zUserOvrd; /* User override. If 0 then use login_name() */
1551 const char *zBranch; /* Branch name. May be 0 */
1552 const char *zColor; /* One-time background color. May be 0 */
@@ -2090,10 +2130,12 @@
2090 ** --integrate close all merged-in branches
2091 ** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment
2092 ** -M|--message-file FILE read the commit comment from given file
2093 ** --mimetype MIMETYPE mimetype of check-in comment
2094 ** -n|--dry-run If given, display instead of run actions
 
 
2095 ** --no-prompt This option disables prompting the user for
2096 ** input and assumes an answer of 'No' for every
2097 ** question.
2098 ** --no-warnings omit all warnings about file contents
2099 ** --no-verify do not run before-commit hooks
@@ -2194,10 +2236,11 @@
2194 sCiInfo.zColor = find_option("bgcolor",0,1);
2195 sCiInfo.zBrClr = find_option("branchcolor",0,1);
2196 sCiInfo.closeFlag = find_option("close",0,0)!=0;
2197 sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
2198 sCiInfo.zMimetype = find_option("mimetype",0,1);
 
2199 while( (zTag = find_option("tag",0,1))!=0 ){
2200 if( zTag[0]==0 ) continue;
2201 sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
2202 sizeof(char*)*(nTag+2));
2203 sCiInfo.azTag[nTag++] = zTag;
2204
--- src/checkin.c
+++ src/checkin.c
@@ -1237,10 +1237,15 @@
1237 int i, n;
1238 char *z;
1239 n = blob_size(&line);
1240 z = blob_buffer(&line);
1241 for(i=0; i<n && fossil_isspace(z[i]); i++){}
1242 if( fossil_strncmp(
1243 "# NOTE: The below diff is not inserted into the commit message.\n",
1244 z, n)==0 ){
1245 break;
1246 }
1247 if( i<n && z[i]=='#' ) continue;
1248 if( i<n || blob_size(pComment)>0 ){
1249 blob_appendf(pComment, "%b", &line);
1250 }
1251 }
@@ -1324,10 +1329,44 @@
1329 blob_append(&prompt,
1330 "#\n"
1331 "# All merged-in branches will be closed due to the --integrate flag\n"
1332 "#\n", -1
1333 );
1334 }
1335 if( p->verboseFlag ){
1336 blob_append(&prompt,
1337 "#\n"
1338 "# NOTE: The below diff is not inserted into the commit message.\n\n",
1339 -1
1340 );
1341 if( g.aCommitFile ){
1342 FileDirList *diffFiles;
1343 int i;
1344 diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles));
1345 for( i=0; g.aCommitFile[i]!=0; ++i ){
1346 diffFiles[i].zName = db_text(0,
1347 "SELECT pathname FROM vfile WHERE id=%d", g.aCommitFile[i]);
1348 if( fossil_strcmp(diffFiles[i].zName, "." )==0 ){
1349 diffFiles[0].zName[0] = '.';
1350 diffFiles[0].zName[1] = 0;
1351 break;
1352 }
1353 diffFiles[i].nName = strlen(diffFiles[i].zName);
1354 diffFiles[i].nUsed = 0;
1355 }
1356 diff_against_disk(0, 0, diff_get_binary_glob(),
1357 db_get_boolean("diff-binary", 1),
1358 DIFF_VERBOSE, diffFiles, &prompt);
1359 for( i=0; diffFiles[i].zName; ++i ){
1360 fossil_free(diffFiles[i].zName);
1361 }
1362 fossil_free(diffFiles);
1363 }else{
1364 diff_against_disk(0, 0, diff_get_binary_glob(),
1365 db_get_boolean("diff-binary", 1),
1366 DIFF_VERBOSE, 0, &prompt);
1367 }
1368 }
1369 prompt_for_user_comment(pComment, &prompt);
1370 blob_reset(&prompt);
1371 }
1372
@@ -1543,10 +1582,11 @@
1582 Blob *pComment; /* Check-in comment text */
1583 const char *zMimetype; /* Mimetype of check-in command. May be NULL */
1584 int verifyDate; /* Verify that child is younger */
1585 int closeFlag; /* Close the branch being committed */
1586 int integrateFlag; /* Close merged-in branches */
1587 int verboseFlag; /* Show diff in editor for check-in comment */
1588 Blob *pCksum; /* Repository checksum. May be 0 */
1589 const char *zDateOvrd; /* Date override. If 0 then use 'now' */
1590 const char *zUserOvrd; /* User override. If 0 then use login_name() */
1591 const char *zBranch; /* Branch name. May be 0 */
1592 const char *zColor; /* One-time background color. May be 0 */
@@ -2090,10 +2130,12 @@
2130 ** --integrate close all merged-in branches
2131 ** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment
2132 ** -M|--message-file FILE read the commit comment from given file
2133 ** --mimetype MIMETYPE mimetype of check-in comment
2134 ** -n|--dry-run If given, display instead of run actions
2135 ** -v|--verbose Display in the editor a unified diff of the
2136 ** changes to be committed with this check-in
2137 ** --no-prompt This option disables prompting the user for
2138 ** input and assumes an answer of 'No' for every
2139 ** question.
2140 ** --no-warnings omit all warnings about file contents
2141 ** --no-verify do not run before-commit hooks
@@ -2194,10 +2236,11 @@
2236 sCiInfo.zColor = find_option("bgcolor",0,1);
2237 sCiInfo.zBrClr = find_option("branchcolor",0,1);
2238 sCiInfo.closeFlag = find_option("close",0,0)!=0;
2239 sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
2240 sCiInfo.zMimetype = find_option("mimetype",0,1);
2241 sCiInfo.verboseFlag = find_option("verbose", "v", 0)!=0;
2242 while( (zTag = find_option("tag",0,1))!=0 ){
2243 if( zTag[0]==0 ) continue;
2244 sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
2245 sizeof(char*)*(nTag+2));
2246 sCiInfo.azTag[nTag++] = zTag;
2247
+1 -1
--- src/diff.c
+++ src/diff.c
@@ -2090,11 +2090,11 @@
20902090
if( zErr ) fossil_fatal("regex error: %s", zErr);
20912091
}
20922092
diffFlag = diff_options();
20932093
verify_all_options();
20942094
if( g.argc!=4 ) usage("FILE1 FILE2");
2095
- diff_print_filenames(g.argv[2], g.argv[3], diffFlag);
2095
+ diff_print_filenames(g.argv[2], g.argv[3], diffFlag, 0);
20962096
blob_read_from_file(&a, g.argv[2], ExtFILE);
20972097
blob_read_from_file(&b, g.argv[3], ExtFILE);
20982098
blob_zero(&out);
20992099
text_diff(&a, &b, &out, pRe, diffFlag);
21002100
blob_write_to_file(&out, "-");
21012101
--- src/diff.c
+++ src/diff.c
@@ -2090,11 +2090,11 @@
2090 if( zErr ) fossil_fatal("regex error: %s", zErr);
2091 }
2092 diffFlag = diff_options();
2093 verify_all_options();
2094 if( g.argc!=4 ) usage("FILE1 FILE2");
2095 diff_print_filenames(g.argv[2], g.argv[3], diffFlag);
2096 blob_read_from_file(&a, g.argv[2], ExtFILE);
2097 blob_read_from_file(&b, g.argv[3], ExtFILE);
2098 blob_zero(&out);
2099 text_diff(&a, &b, &out, pRe, diffFlag);
2100 blob_write_to_file(&out, "-");
2101
--- src/diff.c
+++ src/diff.c
@@ -2090,11 +2090,11 @@
2090 if( zErr ) fossil_fatal("regex error: %s", zErr);
2091 }
2092 diffFlag = diff_options();
2093 verify_all_options();
2094 if( g.argc!=4 ) usage("FILE1 FILE2");
2095 diff_print_filenames(g.argv[2], g.argv[3], diffFlag, 0);
2096 blob_read_from_file(&a, g.argv[2], ExtFILE);
2097 blob_read_from_file(&b, g.argv[3], ExtFILE);
2098 blob_zero(&out);
2099 text_diff(&a, &b, &out, pRe, diffFlag);
2100 blob_write_to_file(&out, "-");
2101
+38 -18
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -106,22 +106,27 @@
106106
}
107107
108108
/*
109109
** Print the "Index:" message that patches wants to see at the top of a diff.
110110
*/
111
-void diff_print_index(const char *zFile, u64 diffFlags){
111
+void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
112112
if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113113
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114
- fossil_print("%s", z);
114
+ if( !diffBlob ){
115
+ fossil_print("%s", z);
116
+ }else{
117
+ blob_appendf(diffBlob, "%s", z);
118
+ }
115119
fossil_free(z);
116120
}
117121
}
118122
119123
/*
120124
** Print the +++/--- filename lines for a diff operation.
121125
*/
122
-void diff_print_filenames(const char *zLeft, const char *zRight, u64 diffFlags){
126
+void diff_print_filenames(const char *zLeft, const char *zRight,
127
+ u64 diffFlags, Blob *diffBlob){
123128
char *z = 0;
124129
if( diffFlags & DIFF_BRIEF ){
125130
/* no-op */
126131
}else if( diffFlags & DIFF_SIDEBYSIDE ){
127132
int w = diff_width(diffFlags);
@@ -142,11 +147,15 @@
142147
(w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
143148
}
144149
}else{
145150
z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
146151
}
147
- fossil_print("%s", z);
152
+ if( !diffBlob ){
153
+ fossil_print("%s", z);
154
+ }else{
155
+ blob_appendf(diffBlob, "%s", z);
156
+ }
148157
fossil_free(z);
149158
}
150159
151160
/*
152161
** Show the difference between two files, one in memory and one on disk.
@@ -171,11 +180,12 @@
171180
const char *zName, /* Display name of the file */
172181
const char *zDiffCmd, /* Command for comparison */
173182
const char *zBinGlob, /* Treat file names matching this as binary */
174183
int fIncludeBinary, /* Include binary files for external diff */
175184
u64 diffFlags, /* Flags to control the diff */
176
- int fSwapDiff /* Diff from Zfile2 to Pfile1 */
185
+ int fSwapDiff, /* Diff from Zfile2 to Pfile1 */
186
+ Blob *diffBlob /* Blob to store diff output */
177187
){
178188
if( zDiffCmd==0 ){
179189
Blob out; /* Diff output text */
180190
Blob file2; /* Content of zFile2 */
181191
const char *zName2; /* Name of zFile2 for display */
@@ -201,14 +211,23 @@
201211
}else{
202212
text_diff(pFile1, &file2, &out, 0, diffFlags);
203213
}
204214
if( blob_size(&out) ){
205215
if( diffFlags & DIFF_NUMSTAT ){
206
- fossil_print("%s %s\n", blob_str(&out), zName);
216
+ if( !diffBlob ){
217
+ fossil_print("%s %s\n", blob_str(&out), zName);
218
+ }else{
219
+ blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName);
220
+ }
207221
}else{
208
- diff_print_filenames(zName, zName2, diffFlags);
209
- fossil_print("%s\n", blob_str(&out));
222
+ if( !diffBlob ){
223
+ diff_print_filenames(zName, zName2, diffFlags, 0);
224
+ fossil_print("%s\n", blob_str(&out));
225
+ }else{
226
+ diff_print_filenames(zName, zName2, diffFlags, diffBlob);
227
+ blob_appendf(diffBlob, "%s\n", blob_str(&out));
228
+ }
210229
}
211230
}
212231
blob_reset(&out);
213232
}
214233
@@ -302,11 +321,11 @@
302321
blob_zero(&out);
303322
text_diff(pFile1, pFile2, &out, 0, diffFlags);
304323
if( diffFlags & DIFF_NUMSTAT ){
305324
fossil_print("%s %s\n", blob_str(&out), zName);
306325
}else{
307
- diff_print_filenames(zName, zName, diffFlags);
326
+ diff_print_filenames(zName, zName, diffFlags, 0);
308327
fossil_print("%s\n", blob_str(&out));
309328
}
310329
311330
/* Release memory resources */
312331
blob_reset(&out);
@@ -366,17 +385,18 @@
366385
**
367386
** When using an external diff program, zBinGlob contains the GLOB patterns
368387
** for file names to treat as binary. If fIncludeBinary is zero, these files
369388
** will be skipped in addition to files that may contain binary content.
370389
*/
371
-static void diff_against_disk(
390
+void diff_against_disk(
372391
const char *zFrom, /* Version to difference from */
373392
const char *zDiffCmd, /* Use this diff command. NULL for built-in */
374393
const char *zBinGlob, /* Treat file names matching this as binary */
375394
int fIncludeBinary, /* Treat file names matching this as binary */
376395
u64 diffFlags, /* Flags controlling diff output */
377
- FileDirList *pFileDir /* Which files to diff */
396
+ FileDirList *pFileDir, /* Which files to diff */
397
+ Blob *diffBlob /* Blob to output diff instead of stdout */
378398
){
379399
int vid;
380400
Blob sql;
381401
Stmt q;
382402
int asNewFile; /* Treat non-existant files as empty files */
@@ -467,24 +487,24 @@
467487
}
468488
if( showDiff ){
469489
Blob content;
470490
int isBin;
471491
if( !isLink != !file_islink(zFullName) ){
472
- diff_print_index(zPathname, diffFlags);
473
- diff_print_filenames(zPathname, zPathname, diffFlags);
492
+ diff_print_index(zPathname, diffFlags, 0);
493
+ diff_print_filenames(zPathname, zPathname, diffFlags, 0);
474494
fossil_print("%s",DIFF_CANNOT_COMPUTE_SYMLINK);
475495
continue;
476496
}
477497
if( srcid>0 ){
478498
content_get(srcid, &content);
479499
}else{
480500
blob_zero(&content);
481501
}
482502
isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
483
- diff_print_index(zPathname, diffFlags);
503
+ diff_print_index(zPathname, diffFlags, diffBlob);
484504
diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
485
- zBinGlob, fIncludeBinary, diffFlags, 0);
505
+ zBinGlob, fIncludeBinary, diffFlags, 0, diffBlob);
486506
blob_reset(&content);
487507
}
488508
blob_reset(&fname);
489509
}
490510
db_finalize(&q);
@@ -517,11 +537,11 @@
517537
const char *zFile = (const char*)db_column_text(&q, 0);
518538
if( !file_dir_match(pFileDir, zFile) ) continue;
519539
zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
520540
db_column_blob(&q, 1, &content);
521541
diff_file(&content, 0, zFullName, zFile,
522
- zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0);
542
+ zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0, 0);
523543
fossil_free(zFullName);
524544
blob_reset(&content);
525545
}
526546
db_finalize(&q);
527547
}
@@ -555,11 +575,11 @@
555575
zName = pTo->zName;
556576
}else{
557577
zName = DIFF_NO_NAME;
558578
}
559579
if( diffFlags & DIFF_BRIEF ) return;
560
- diff_print_index(zName, diffFlags);
580
+ diff_print_index(zName, diffFlags, 0);
561581
if( pFrom ){
562582
rid = uuid_to_rid(pFrom->zUuid, 0);
563583
content_get(rid, &f1);
564584
}else{
565585
blob_zero(&f1);
@@ -941,11 +961,11 @@
941961
}
942962
diff_against_undo(zDiffCmd, zBinGlob, fIncludeBinary,
943963
diffFlags, pFileDir);
944964
}else if( zTo==0 ){
945965
diff_against_disk(zFrom, zDiffCmd, zBinGlob, fIncludeBinary,
946
- diffFlags, pFileDir);
966
+ diffFlags, pFileDir, 0);
947967
}else{
948968
diff_two_versions(zFrom, zTo, zDiffCmd, zBinGlob, fIncludeBinary,
949969
diffFlags, pFileDir);
950970
}
951971
if( pFileDir ){
952972
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -106,22 +106,27 @@
106 }
107
108 /*
109 ** Print the "Index:" message that patches wants to see at the top of a diff.
110 */
111 void diff_print_index(const char *zFile, u64 diffFlags){
112 if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114 fossil_print("%s", z);
 
 
 
 
115 fossil_free(z);
116 }
117 }
118
119 /*
120 ** Print the +++/--- filename lines for a diff operation.
121 */
122 void diff_print_filenames(const char *zLeft, const char *zRight, u64 diffFlags){
 
123 char *z = 0;
124 if( diffFlags & DIFF_BRIEF ){
125 /* no-op */
126 }else if( diffFlags & DIFF_SIDEBYSIDE ){
127 int w = diff_width(diffFlags);
@@ -142,11 +147,15 @@
142 (w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
143 }
144 }else{
145 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
146 }
147 fossil_print("%s", z);
 
 
 
 
148 fossil_free(z);
149 }
150
151 /*
152 ** Show the difference between two files, one in memory and one on disk.
@@ -171,11 +180,12 @@
171 const char *zName, /* Display name of the file */
172 const char *zDiffCmd, /* Command for comparison */
173 const char *zBinGlob, /* Treat file names matching this as binary */
174 int fIncludeBinary, /* Include binary files for external diff */
175 u64 diffFlags, /* Flags to control the diff */
176 int fSwapDiff /* Diff from Zfile2 to Pfile1 */
 
177 ){
178 if( zDiffCmd==0 ){
179 Blob out; /* Diff output text */
180 Blob file2; /* Content of zFile2 */
181 const char *zName2; /* Name of zFile2 for display */
@@ -201,14 +211,23 @@
201 }else{
202 text_diff(pFile1, &file2, &out, 0, diffFlags);
203 }
204 if( blob_size(&out) ){
205 if( diffFlags & DIFF_NUMSTAT ){
206 fossil_print("%s %s\n", blob_str(&out), zName);
 
 
 
 
207 }else{
208 diff_print_filenames(zName, zName2, diffFlags);
209 fossil_print("%s\n", blob_str(&out));
 
 
 
 
 
210 }
211 }
212 blob_reset(&out);
213 }
214
@@ -302,11 +321,11 @@
302 blob_zero(&out);
303 text_diff(pFile1, pFile2, &out, 0, diffFlags);
304 if( diffFlags & DIFF_NUMSTAT ){
305 fossil_print("%s %s\n", blob_str(&out), zName);
306 }else{
307 diff_print_filenames(zName, zName, diffFlags);
308 fossil_print("%s\n", blob_str(&out));
309 }
310
311 /* Release memory resources */
312 blob_reset(&out);
@@ -366,17 +385,18 @@
366 **
367 ** When using an external diff program, zBinGlob contains the GLOB patterns
368 ** for file names to treat as binary. If fIncludeBinary is zero, these files
369 ** will be skipped in addition to files that may contain binary content.
370 */
371 static void diff_against_disk(
372 const char *zFrom, /* Version to difference from */
373 const char *zDiffCmd, /* Use this diff command. NULL for built-in */
374 const char *zBinGlob, /* Treat file names matching this as binary */
375 int fIncludeBinary, /* Treat file names matching this as binary */
376 u64 diffFlags, /* Flags controlling diff output */
377 FileDirList *pFileDir /* Which files to diff */
 
378 ){
379 int vid;
380 Blob sql;
381 Stmt q;
382 int asNewFile; /* Treat non-existant files as empty files */
@@ -467,24 +487,24 @@
467 }
468 if( showDiff ){
469 Blob content;
470 int isBin;
471 if( !isLink != !file_islink(zFullName) ){
472 diff_print_index(zPathname, diffFlags);
473 diff_print_filenames(zPathname, zPathname, diffFlags);
474 fossil_print("%s",DIFF_CANNOT_COMPUTE_SYMLINK);
475 continue;
476 }
477 if( srcid>0 ){
478 content_get(srcid, &content);
479 }else{
480 blob_zero(&content);
481 }
482 isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
483 diff_print_index(zPathname, diffFlags);
484 diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
485 zBinGlob, fIncludeBinary, diffFlags, 0);
486 blob_reset(&content);
487 }
488 blob_reset(&fname);
489 }
490 db_finalize(&q);
@@ -517,11 +537,11 @@
517 const char *zFile = (const char*)db_column_text(&q, 0);
518 if( !file_dir_match(pFileDir, zFile) ) continue;
519 zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
520 db_column_blob(&q, 1, &content);
521 diff_file(&content, 0, zFullName, zFile,
522 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0);
523 fossil_free(zFullName);
524 blob_reset(&content);
525 }
526 db_finalize(&q);
527 }
@@ -555,11 +575,11 @@
555 zName = pTo->zName;
556 }else{
557 zName = DIFF_NO_NAME;
558 }
559 if( diffFlags & DIFF_BRIEF ) return;
560 diff_print_index(zName, diffFlags);
561 if( pFrom ){
562 rid = uuid_to_rid(pFrom->zUuid, 0);
563 content_get(rid, &f1);
564 }else{
565 blob_zero(&f1);
@@ -941,11 +961,11 @@
941 }
942 diff_against_undo(zDiffCmd, zBinGlob, fIncludeBinary,
943 diffFlags, pFileDir);
944 }else if( zTo==0 ){
945 diff_against_disk(zFrom, zDiffCmd, zBinGlob, fIncludeBinary,
946 diffFlags, pFileDir);
947 }else{
948 diff_two_versions(zFrom, zTo, zDiffCmd, zBinGlob, fIncludeBinary,
949 diffFlags, pFileDir);
950 }
951 if( pFileDir ){
952
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -106,22 +106,27 @@
106 }
107
108 /*
109 ** Print the "Index:" message that patches wants to see at the top of a diff.
110 */
111 void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
112 if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114 if( !diffBlob ){
115 fossil_print("%s", z);
116 }else{
117 blob_appendf(diffBlob, "%s", z);
118 }
119 fossil_free(z);
120 }
121 }
122
123 /*
124 ** Print the +++/--- filename lines for a diff operation.
125 */
126 void diff_print_filenames(const char *zLeft, const char *zRight,
127 u64 diffFlags, Blob *diffBlob){
128 char *z = 0;
129 if( diffFlags & DIFF_BRIEF ){
130 /* no-op */
131 }else if( diffFlags & DIFF_SIDEBYSIDE ){
132 int w = diff_width(diffFlags);
@@ -142,11 +147,15 @@
147 (w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
148 }
149 }else{
150 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
151 }
152 if( !diffBlob ){
153 fossil_print("%s", z);
154 }else{
155 blob_appendf(diffBlob, "%s", z);
156 }
157 fossil_free(z);
158 }
159
160 /*
161 ** Show the difference between two files, one in memory and one on disk.
@@ -171,11 +180,12 @@
180 const char *zName, /* Display name of the file */
181 const char *zDiffCmd, /* Command for comparison */
182 const char *zBinGlob, /* Treat file names matching this as binary */
183 int fIncludeBinary, /* Include binary files for external diff */
184 u64 diffFlags, /* Flags to control the diff */
185 int fSwapDiff, /* Diff from Zfile2 to Pfile1 */
186 Blob *diffBlob /* Blob to store diff output */
187 ){
188 if( zDiffCmd==0 ){
189 Blob out; /* Diff output text */
190 Blob file2; /* Content of zFile2 */
191 const char *zName2; /* Name of zFile2 for display */
@@ -201,14 +211,23 @@
211 }else{
212 text_diff(pFile1, &file2, &out, 0, diffFlags);
213 }
214 if( blob_size(&out) ){
215 if( diffFlags & DIFF_NUMSTAT ){
216 if( !diffBlob ){
217 fossil_print("%s %s\n", blob_str(&out), zName);
218 }else{
219 blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName);
220 }
221 }else{
222 if( !diffBlob ){
223 diff_print_filenames(zName, zName2, diffFlags, 0);
224 fossil_print("%s\n", blob_str(&out));
225 }else{
226 diff_print_filenames(zName, zName2, diffFlags, diffBlob);
227 blob_appendf(diffBlob, "%s\n", blob_str(&out));
228 }
229 }
230 }
231 blob_reset(&out);
232 }
233
@@ -302,11 +321,11 @@
321 blob_zero(&out);
322 text_diff(pFile1, pFile2, &out, 0, diffFlags);
323 if( diffFlags & DIFF_NUMSTAT ){
324 fossil_print("%s %s\n", blob_str(&out), zName);
325 }else{
326 diff_print_filenames(zName, zName, diffFlags, 0);
327 fossil_print("%s\n", blob_str(&out));
328 }
329
330 /* Release memory resources */
331 blob_reset(&out);
@@ -366,17 +385,18 @@
385 **
386 ** When using an external diff program, zBinGlob contains the GLOB patterns
387 ** for file names to treat as binary. If fIncludeBinary is zero, these files
388 ** will be skipped in addition to files that may contain binary content.
389 */
390 void diff_against_disk(
391 const char *zFrom, /* Version to difference from */
392 const char *zDiffCmd, /* Use this diff command. NULL for built-in */
393 const char *zBinGlob, /* Treat file names matching this as binary */
394 int fIncludeBinary, /* Treat file names matching this as binary */
395 u64 diffFlags, /* Flags controlling diff output */
396 FileDirList *pFileDir, /* Which files to diff */
397 Blob *diffBlob /* Blob to output diff instead of stdout */
398 ){
399 int vid;
400 Blob sql;
401 Stmt q;
402 int asNewFile; /* Treat non-existant files as empty files */
@@ -467,24 +487,24 @@
487 }
488 if( showDiff ){
489 Blob content;
490 int isBin;
491 if( !isLink != !file_islink(zFullName) ){
492 diff_print_index(zPathname, diffFlags, 0);
493 diff_print_filenames(zPathname, zPathname, diffFlags, 0);
494 fossil_print("%s",DIFF_CANNOT_COMPUTE_SYMLINK);
495 continue;
496 }
497 if( srcid>0 ){
498 content_get(srcid, &content);
499 }else{
500 blob_zero(&content);
501 }
502 isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
503 diff_print_index(zPathname, diffFlags, diffBlob);
504 diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
505 zBinGlob, fIncludeBinary, diffFlags, 0, diffBlob);
506 blob_reset(&content);
507 }
508 blob_reset(&fname);
509 }
510 db_finalize(&q);
@@ -517,11 +537,11 @@
537 const char *zFile = (const char*)db_column_text(&q, 0);
538 if( !file_dir_match(pFileDir, zFile) ) continue;
539 zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
540 db_column_blob(&q, 1, &content);
541 diff_file(&content, 0, zFullName, zFile,
542 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0, 0);
543 fossil_free(zFullName);
544 blob_reset(&content);
545 }
546 db_finalize(&q);
547 }
@@ -555,11 +575,11 @@
575 zName = pTo->zName;
576 }else{
577 zName = DIFF_NO_NAME;
578 }
579 if( diffFlags & DIFF_BRIEF ) return;
580 diff_print_index(zName, diffFlags, 0);
581 if( pFrom ){
582 rid = uuid_to_rid(pFrom->zUuid, 0);
583 content_get(rid, &f1);
584 }else{
585 blob_zero(&f1);
@@ -941,11 +961,11 @@
961 }
962 diff_against_undo(zDiffCmd, zBinGlob, fIncludeBinary,
963 diffFlags, pFileDir);
964 }else if( zTo==0 ){
965 diff_against_disk(zFrom, zDiffCmd, zBinGlob, fIncludeBinary,
966 diffFlags, pFileDir, 0);
967 }else{
968 diff_two_versions(zFrom, zTo, zDiffCmd, zBinGlob, fIncludeBinary,
969 diffFlags, pFileDir);
970 }
971 if( pFileDir ){
972
+5 -5
--- src/stash.c
+++ src/stash.c
@@ -428,18 +428,18 @@
428428
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
429429
Blob a, b;
430430
if( rid==0 ){
431431
db_ephemeral_blob(&q, 6, &a);
432432
fossil_print("ADDED %s\n", zNew);
433
- diff_print_index(zNew, diffFlags);
433
+ diff_print_index(zNew, diffFlags, 0);
434434
isBin1 = 0;
435435
isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
436436
diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
437437
zBinGlob, fIncludeBinary, diffFlags);
438438
}else if( isRemoved ){
439439
fossil_print("DELETE %s\n", zOrig);
440
- diff_print_index(zNew, diffFlags);
440
+ diff_print_index(zNew, diffFlags, 0);
441441
isBin2 = 0;
442442
if( fBaseline ){
443443
content_get(rid, &a);
444444
isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
445445
diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
@@ -450,12 +450,12 @@
450450
Blob delta;
451451
int isOrigLink = file_islink(zOPath);
452452
db_ephemeral_blob(&q, 6, &delta);
453453
fossil_print("CHANGED %s\n", zNew);
454454
if( !isOrigLink != !isLink ){
455
- diff_print_index(zNew, diffFlags);
456
- diff_print_filenames(zOrig, zNew, diffFlags);
455
+ diff_print_index(zNew, diffFlags, 0);
456
+ diff_print_filenames(zOrig, zNew, diffFlags, 0);
457457
printf(DIFF_CANNOT_COMPUTE_SYMLINK);
458458
}else{
459459
content_get(rid, &a);
460460
blob_delta_apply(&a, &delta, &b);
461461
isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
@@ -465,11 +465,11 @@
465465
zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
466466
}else{
467467
/*Diff with file on disk using fSwapDiff=1 to show the diff in the
468468
same direction as if fBaseline=1.*/
469469
diff_file(&b, isBin2, zOPath, zNew, zDiffCmd,
470
- zBinGlob, fIncludeBinary, diffFlags, 1);
470
+ zBinGlob, fIncludeBinary, diffFlags, 1, 0);
471471
}
472472
blob_reset(&a);
473473
blob_reset(&b);
474474
}
475475
blob_reset(&delta);
476476
--- src/stash.c
+++ src/stash.c
@@ -428,18 +428,18 @@
428 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
429 Blob a, b;
430 if( rid==0 ){
431 db_ephemeral_blob(&q, 6, &a);
432 fossil_print("ADDED %s\n", zNew);
433 diff_print_index(zNew, diffFlags);
434 isBin1 = 0;
435 isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
436 diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
437 zBinGlob, fIncludeBinary, diffFlags);
438 }else if( isRemoved ){
439 fossil_print("DELETE %s\n", zOrig);
440 diff_print_index(zNew, diffFlags);
441 isBin2 = 0;
442 if( fBaseline ){
443 content_get(rid, &a);
444 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
445 diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
@@ -450,12 +450,12 @@
450 Blob delta;
451 int isOrigLink = file_islink(zOPath);
452 db_ephemeral_blob(&q, 6, &delta);
453 fossil_print("CHANGED %s\n", zNew);
454 if( !isOrigLink != !isLink ){
455 diff_print_index(zNew, diffFlags);
456 diff_print_filenames(zOrig, zNew, diffFlags);
457 printf(DIFF_CANNOT_COMPUTE_SYMLINK);
458 }else{
459 content_get(rid, &a);
460 blob_delta_apply(&a, &delta, &b);
461 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
@@ -465,11 +465,11 @@
465 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
466 }else{
467 /*Diff with file on disk using fSwapDiff=1 to show the diff in the
468 same direction as if fBaseline=1.*/
469 diff_file(&b, isBin2, zOPath, zNew, zDiffCmd,
470 zBinGlob, fIncludeBinary, diffFlags, 1);
471 }
472 blob_reset(&a);
473 blob_reset(&b);
474 }
475 blob_reset(&delta);
476
--- src/stash.c
+++ src/stash.c
@@ -428,18 +428,18 @@
428 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
429 Blob a, b;
430 if( rid==0 ){
431 db_ephemeral_blob(&q, 6, &a);
432 fossil_print("ADDED %s\n", zNew);
433 diff_print_index(zNew, diffFlags, 0);
434 isBin1 = 0;
435 isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
436 diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
437 zBinGlob, fIncludeBinary, diffFlags);
438 }else if( isRemoved ){
439 fossil_print("DELETE %s\n", zOrig);
440 diff_print_index(zNew, diffFlags, 0);
441 isBin2 = 0;
442 if( fBaseline ){
443 content_get(rid, &a);
444 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
445 diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
@@ -450,12 +450,12 @@
450 Blob delta;
451 int isOrigLink = file_islink(zOPath);
452 db_ephemeral_blob(&q, 6, &delta);
453 fossil_print("CHANGED %s\n", zNew);
454 if( !isOrigLink != !isLink ){
455 diff_print_index(zNew, diffFlags, 0);
456 diff_print_filenames(zOrig, zNew, diffFlags, 0);
457 printf(DIFF_CANNOT_COMPUTE_SYMLINK);
458 }else{
459 content_get(rid, &a);
460 blob_delta_apply(&a, &delta, &b);
461 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
@@ -465,11 +465,11 @@
465 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
466 }else{
467 /*Diff with file on disk using fSwapDiff=1 to show the diff in the
468 same direction as if fBaseline=1.*/
469 diff_file(&b, isBin2, zOPath, zNew, zDiffCmd,
470 zBinGlob, fIncludeBinary, diffFlags, 1, 0);
471 }
472 blob_reset(&a);
473 blob_reset(&b);
474 }
475 blob_reset(&delta);
476

Keyboard Shortcuts

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