Fossil SCM

Add the --brief option to the "diff" command.

drh 2012-02-07 15:38 trunk
Commit e0565d43513cbefdaa0a6ae7605ad0e1950c9acd
2 files changed +8 -3 +19 -6
+8 -3
--- src/diff.c
+++ src/diff.c
@@ -30,11 +30,12 @@
3030
#define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */
3131
#define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */
3232
#define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */
3333
#define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */
3434
#define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */
35
-#define DIFF_INLINE 0x08000000 /* Inline (not side-by-side) diff */
35
+#define DIFF_BRIEF 0x08000000 /* Show filenames only */
36
+#define DIFF_INLINE 0x00000000 /* Inline (not side-by-side) diff */
3637
#define DIFF_HTML 0x10000000 /* Render for HTML */
3738
#define DIFF_LINENO 0x20000000 /* Show line numbers in context diff */
3839
#define DIFF_NOOPT 0x40000000 /* Suppress optimizations for debug */
3940
#define DIFF_INVERT 0x80000000 /* Invert the diff for debug */
4041
@@ -1331,15 +1332,18 @@
13311332
13321333
/*
13331334
** Process diff-related command-line options and return an appropriate
13341335
** "diffFlags" integer.
13351336
**
1336
-** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
1337
+** --brief Show filenames only DIFF_BRIEF
13371338
** --context|-c N N lines of context. DIFF_CONTEXT_MASK
1338
-** --width|-W N N character lines. DIFF_WIDTH_MASK
13391339
** --html Format for HTML DIFF_HTML
1340
+** --invert Invert the diff DIFF_INVERT
13401341
** --linenum|-n Show line numbers DIFF_LINENO
1342
+** --noopt Disable optimization DIFF_NOOPT
1343
+** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
1344
+** --width|-W N N character lines. DIFF_WIDTH_MASK
13411345
*/
13421346
int diff_options(void){
13431347
int diffFlags = 0;
13441348
const char *z;
13451349
int f;
@@ -1355,10 +1359,11 @@
13551359
}
13561360
if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
13571361
if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
13581362
if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
13591363
if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
1364
+ if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
13601365
return diffFlags;
13611366
}
13621367
13631368
/*
13641369
** COMMAND: test-rawdiff
13651370
--- src/diff.c
+++ src/diff.c
@@ -30,11 +30,12 @@
30 #define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */
31 #define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */
32 #define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */
33 #define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */
34 #define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */
35 #define DIFF_INLINE 0x08000000 /* Inline (not side-by-side) diff */
 
36 #define DIFF_HTML 0x10000000 /* Render for HTML */
37 #define DIFF_LINENO 0x20000000 /* Show line numbers in context diff */
38 #define DIFF_NOOPT 0x40000000 /* Suppress optimizations for debug */
39 #define DIFF_INVERT 0x80000000 /* Invert the diff for debug */
40
@@ -1331,15 +1332,18 @@
1331
1332 /*
1333 ** Process diff-related command-line options and return an appropriate
1334 ** "diffFlags" integer.
1335 **
1336 ** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
1337 ** --context|-c N N lines of context. DIFF_CONTEXT_MASK
1338 ** --width|-W N N character lines. DIFF_WIDTH_MASK
1339 ** --html Format for HTML DIFF_HTML
 
1340 ** --linenum|-n Show line numbers DIFF_LINENO
 
 
 
1341 */
1342 int diff_options(void){
1343 int diffFlags = 0;
1344 const char *z;
1345 int f;
@@ -1355,10 +1359,11 @@
1355 }
1356 if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
1357 if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
1358 if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
1359 if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
 
1360 return diffFlags;
1361 }
1362
1363 /*
1364 ** COMMAND: test-rawdiff
1365
--- src/diff.c
+++ src/diff.c
@@ -30,11 +30,12 @@
30 #define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */
31 #define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */
32 #define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */
33 #define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */
34 #define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */
35 #define DIFF_BRIEF 0x08000000 /* Show filenames only */
36 #define DIFF_INLINE 0x00000000 /* Inline (not side-by-side) diff */
37 #define DIFF_HTML 0x10000000 /* Render for HTML */
38 #define DIFF_LINENO 0x20000000 /* Show line numbers in context diff */
39 #define DIFF_NOOPT 0x40000000 /* Suppress optimizations for debug */
40 #define DIFF_INVERT 0x80000000 /* Invert the diff for debug */
41
@@ -1331,15 +1332,18 @@
1332
1333 /*
1334 ** Process diff-related command-line options and return an appropriate
1335 ** "diffFlags" integer.
1336 **
1337 ** --brief Show filenames only DIFF_BRIEF
1338 ** --context|-c N N lines of context. DIFF_CONTEXT_MASK
 
1339 ** --html Format for HTML DIFF_HTML
1340 ** --invert Invert the diff DIFF_INVERT
1341 ** --linenum|-n Show line numbers DIFF_LINENO
1342 ** --noopt Disable optimization DIFF_NOOPT
1343 ** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
1344 ** --width|-W N N character lines. DIFF_WIDTH_MASK
1345 */
1346 int diff_options(void){
1347 int diffFlags = 0;
1348 const char *z;
1349 int f;
@@ -1355,10 +1359,11 @@
1359 }
1360 if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
1361 if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
1362 if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
1363 if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
1364 if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
1365 return diffFlags;
1366 }
1367
1368 /*
1369 ** COMMAND: test-rawdiff
1370
+19 -6
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -23,11 +23,11 @@
2323
2424
/*
2525
** Print the "Index:" message that patches wants to see at the top of a diff.
2626
*/
2727
void diff_print_index(const char *zFile, int diffFlags){
28
- if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
28
+ if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF))==0 ){
2929
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
3030
fossil_print("%s", z);
3131
fossil_free(z);
3232
}
3333
}
@@ -35,11 +35,13 @@
3535
/*
3636
** Print the +++/--- filename lines for a diff operation.
3737
*/
3838
void diff_print_filenames(const char *zLeft, const char *zRight, int diffFlags){
3939
char *z = 0;
40
- if( diffFlags & DIFF_SIDEBYSIDE ){
40
+ if( diffFlags & DIFF_BRIEF ){
41
+ /* no-op */
42
+ }else if( diffFlags & DIFF_SIDEBYSIDE ){
4143
int w = diff_width(diffFlags);
4244
int n1 = strlen(zLeft);
4345
int x;
4446
if( n1>w*2 ) n1 = w*2;
4547
x = w*2+17 - (n1+2);
@@ -66,10 +68,11 @@
6668
const char *zFile2, /* On disk content to compare to */
6769
const char *zName, /* Display name of the file */
6870
const char *zDiffCmd, /* Command for comparison */
6971
int diffFlags /* Flags to control the diff */
7072
){
73
+ if( diffFlags & DIFF_BRIEF ) return;
7174
if( zDiffCmd==0 ){
7275
Blob out; /* Diff output text */
7376
Blob file2; /* Content of zFile2 */
7477
const char *zName2; /* Name of zFile2 for display */
7578
@@ -142,10 +145,11 @@
142145
Blob *pFile2, /* In memory content to compare to */
143146
const char *zName, /* Display name of the file */
144147
const char *zDiffCmd, /* Command for comparison */
145148
int diffFlags /* Diff flags */
146149
){
150
+ if( diffFlags & DIFF_BRIEF ) return;
147151
if( zDiffCmd==0 ){
148152
Blob out; /* Diff output text */
149153
150154
blob_zero(&out);
151155
text_diff(pFile1, pFile2, &out, diffFlags);
@@ -193,10 +197,11 @@
193197
const char *zFileTreeName
194198
){
195199
Blob fname;
196200
Blob content;
197201
int isLink;
202
+ if( diffFlags & DIFF_BRIEF ) return;
198203
file_tree_name(zFileTreeName, &fname, 1);
199204
historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
200205
if( !isLink != !file_wd_islink(zFrom) ){
201206
fossil_print("cannot compute difference between "
202207
"symlink and regular file\n");
@@ -287,11 +292,13 @@
287292
}else if( isChnged==3 ){
288293
fossil_print("ADDED_BY_MERGE %s\n", zPathname);
289294
srcid = 0;
290295
if( !asNewFile ){ showDiff = 0; }
291296
}
292
- if( showDiff ){
297
+ if( diffFlags & DIFF_BRIEF ){
298
+ if( showDiff ) fossil_print("CHANGED %s\n", zPathname);
299
+ }else if( showDiff ){
293300
Blob content;
294301
if( !isLink != !file_wd_islink(zFullName) ){
295302
diff_print_index(zPathname, diffFlags);
296303
diff_print_filenames(zPathname, zPathname, diffFlags);
297304
fossil_print("cannot compute difference between "
@@ -326,10 +333,11 @@
326333
){
327334
char *zName;
328335
Blob fname;
329336
Blob v1, v2;
330337
int isLink1, isLink2;
338
+ if( diffFlags & DIFF_BRIEF ) return;
331339
file_tree_name(zFileTreeName, &fname, 1);
332340
zName = blob_str(&fname);
333341
historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
334342
historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
335343
if( isLink1 != isLink2 ){
@@ -355,10 +363,11 @@
355363
int diffFlags
356364
){
357365
Blob f1, f2;
358366
int rid;
359367
const char *zName = pFrom ? pFrom->zName : pTo->zName;
368
+ if( diffFlags & DIFF_BRIEF ) return;
360369
diff_print_index(zName, diffFlags);
361370
if( pFrom ){
362371
rid = uuid_to_rid(pFrom->zUuid, 0);
363372
content_get(rid, &f1);
364373
}else{
@@ -419,12 +428,15 @@
419428
}else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
420429
/* No changes */
421430
pFromFile = manifest_file_next(pFrom,0);
422431
pToFile = manifest_file_next(pTo,0);
423432
}else{
424
- /* fossil_print("CHANGED %s\n", pFromFile->zName); */
425
- diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
433
+ if( diffFlags & DIFF_BRIEF ){
434
+ fossil_print("CHANGED %s\n", pFromFile->zName);
435
+ }else{
436
+ diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
437
+ }
426438
pFromFile = manifest_file_next(pFrom,0);
427439
pToFile = manifest_file_next(pTo,0);
428440
}
429441
}
430442
manifest_destroy(pFrom);
@@ -458,14 +470,15 @@
458470
**
459471
** The "-N" or "--new-file" option causes the complete text of added or
460472
** deleted files to be displayed.
461473
**
462474
** Options:
475
+** --brief Show filenames only
463476
** --context|-c N Use N lines of context
464477
** --from|-r VERSION select VERSION as source for the diff
465
-** --new-file|-N output complete text of added or deleted files
466478
** -i use internal diff logic
479
+** --new-file|-N output complete text of added or deleted files
467480
** --to VERSION select VERSION as target for the diff
468481
** --side-by-side|-y side-by-side diff
469482
** --width|-W N Width of lines in side-by-side diff
470483
*/
471484
void diff_cmd(void){
472485
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -23,11 +23,11 @@
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 }
@@ -35,11 +35,13 @@
35 /*
36 ** Print the +++/--- filename lines for a diff operation.
37 */
38 void diff_print_filenames(const char *zLeft, const char *zRight, int diffFlags){
39 char *z = 0;
40 if( diffFlags & DIFF_SIDEBYSIDE ){
 
 
41 int w = diff_width(diffFlags);
42 int n1 = strlen(zLeft);
43 int x;
44 if( n1>w*2 ) n1 = w*2;
45 x = w*2+17 - (n1+2);
@@ -66,10 +68,11 @@
66 const char *zFile2, /* On disk content to compare to */
67 const char *zName, /* Display name of the file */
68 const char *zDiffCmd, /* Command for comparison */
69 int diffFlags /* Flags to control the diff */
70 ){
 
71 if( zDiffCmd==0 ){
72 Blob out; /* Diff output text */
73 Blob file2; /* Content of zFile2 */
74 const char *zName2; /* Name of zFile2 for display */
75
@@ -142,10 +145,11 @@
142 Blob *pFile2, /* In memory content to compare to */
143 const char *zName, /* Display name of the file */
144 const char *zDiffCmd, /* Command for comparison */
145 int diffFlags /* Diff flags */
146 ){
 
147 if( zDiffCmd==0 ){
148 Blob out; /* Diff output text */
149
150 blob_zero(&out);
151 text_diff(pFile1, pFile2, &out, diffFlags);
@@ -193,10 +197,11 @@
193 const char *zFileTreeName
194 ){
195 Blob fname;
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");
@@ -287,11 +292,13 @@
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 "
@@ -326,10 +333,11 @@
326 ){
327 char *zName;
328 Blob fname;
329 Blob v1, v2;
330 int isLink1, isLink2;
 
331 file_tree_name(zFileTreeName, &fname, 1);
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 ){
@@ -355,10 +363,11 @@
355 int diffFlags
356 ){
357 Blob f1, f2;
358 int rid;
359 const char *zName = pFrom ? pFrom->zName : pTo->zName;
 
360 diff_print_index(zName, diffFlags);
361 if( pFrom ){
362 rid = uuid_to_rid(pFrom->zUuid, 0);
363 content_get(rid, &f1);
364 }else{
@@ -419,12 +428,15 @@
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 manifest_destroy(pFrom);
@@ -458,14 +470,15 @@
458 **
459 ** The "-N" or "--new-file" option causes the complete text of added or
460 ** deleted files to be displayed.
461 **
462 ** Options:
 
463 ** --context|-c N Use N lines of context
464 ** --from|-r VERSION select VERSION as source for the diff
465 ** --new-file|-N output complete text of added or deleted files
466 ** -i use internal diff logic
 
467 ** --to VERSION select VERSION as target for the diff
468 ** --side-by-side|-y side-by-side diff
469 ** --width|-W N Width of lines in side-by-side diff
470 */
471 void diff_cmd(void){
472
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -23,11 +23,11 @@
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|DIFF_BRIEF))==0 ){
29 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
30 fossil_print("%s", z);
31 fossil_free(z);
32 }
33 }
@@ -35,11 +35,13 @@
35 /*
36 ** Print the +++/--- filename lines for a diff operation.
37 */
38 void diff_print_filenames(const char *zLeft, const char *zRight, int diffFlags){
39 char *z = 0;
40 if( diffFlags & DIFF_BRIEF ){
41 /* no-op */
42 }else if( diffFlags & DIFF_SIDEBYSIDE ){
43 int w = diff_width(diffFlags);
44 int n1 = strlen(zLeft);
45 int x;
46 if( n1>w*2 ) n1 = w*2;
47 x = w*2+17 - (n1+2);
@@ -66,10 +68,11 @@
68 const char *zFile2, /* On disk content to compare to */
69 const char *zName, /* Display name of the file */
70 const char *zDiffCmd, /* Command for comparison */
71 int diffFlags /* Flags to control the diff */
72 ){
73 if( diffFlags & DIFF_BRIEF ) return;
74 if( zDiffCmd==0 ){
75 Blob out; /* Diff output text */
76 Blob file2; /* Content of zFile2 */
77 const char *zName2; /* Name of zFile2 for display */
78
@@ -142,10 +145,11 @@
145 Blob *pFile2, /* In memory content to compare to */
146 const char *zName, /* Display name of the file */
147 const char *zDiffCmd, /* Command for comparison */
148 int diffFlags /* Diff flags */
149 ){
150 if( diffFlags & DIFF_BRIEF ) return;
151 if( zDiffCmd==0 ){
152 Blob out; /* Diff output text */
153
154 blob_zero(&out);
155 text_diff(pFile1, pFile2, &out, diffFlags);
@@ -193,10 +197,11 @@
197 const char *zFileTreeName
198 ){
199 Blob fname;
200 Blob content;
201 int isLink;
202 if( diffFlags & DIFF_BRIEF ) return;
203 file_tree_name(zFileTreeName, &fname, 1);
204 historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
205 if( !isLink != !file_wd_islink(zFrom) ){
206 fossil_print("cannot compute difference between "
207 "symlink and regular file\n");
@@ -287,11 +292,13 @@
292 }else if( isChnged==3 ){
293 fossil_print("ADDED_BY_MERGE %s\n", zPathname);
294 srcid = 0;
295 if( !asNewFile ){ showDiff = 0; }
296 }
297 if( diffFlags & DIFF_BRIEF ){
298 if( showDiff ) fossil_print("CHANGED %s\n", zPathname);
299 }else if( showDiff ){
300 Blob content;
301 if( !isLink != !file_wd_islink(zFullName) ){
302 diff_print_index(zPathname, diffFlags);
303 diff_print_filenames(zPathname, zPathname, diffFlags);
304 fossil_print("cannot compute difference between "
@@ -326,10 +333,11 @@
333 ){
334 char *zName;
335 Blob fname;
336 Blob v1, v2;
337 int isLink1, isLink2;
338 if( diffFlags & DIFF_BRIEF ) return;
339 file_tree_name(zFileTreeName, &fname, 1);
340 zName = blob_str(&fname);
341 historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
342 historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
343 if( isLink1 != isLink2 ){
@@ -355,10 +363,11 @@
363 int diffFlags
364 ){
365 Blob f1, f2;
366 int rid;
367 const char *zName = pFrom ? pFrom->zName : pTo->zName;
368 if( diffFlags & DIFF_BRIEF ) return;
369 diff_print_index(zName, diffFlags);
370 if( pFrom ){
371 rid = uuid_to_rid(pFrom->zUuid, 0);
372 content_get(rid, &f1);
373 }else{
@@ -419,12 +428,15 @@
428 }else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
429 /* No changes */
430 pFromFile = manifest_file_next(pFrom,0);
431 pToFile = manifest_file_next(pTo,0);
432 }else{
433 if( diffFlags & DIFF_BRIEF ){
434 fossil_print("CHANGED %s\n", pFromFile->zName);
435 }else{
436 diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
437 }
438 pFromFile = manifest_file_next(pFrom,0);
439 pToFile = manifest_file_next(pTo,0);
440 }
441 }
442 manifest_destroy(pFrom);
@@ -458,14 +470,15 @@
470 **
471 ** The "-N" or "--new-file" option causes the complete text of added or
472 ** deleted files to be displayed.
473 **
474 ** Options:
475 ** --brief Show filenames only
476 ** --context|-c N Use N lines of context
477 ** --from|-r VERSION select VERSION as source for the diff
 
478 ** -i use internal diff logic
479 ** --new-file|-N output complete text of added or deleted files
480 ** --to VERSION select VERSION as target for the diff
481 ** --side-by-side|-y side-by-side diff
482 ** --width|-W N Width of lines in side-by-side diff
483 */
484 void diff_cmd(void){
485

Keyboard Shortcuts

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