Hi Richard,
please, find attached a patch that introduces "--brief" (short "-q")
option to "fossil diff" that acts analogous to regular "diff --brief"
or "diff -q". It suppresses diff contents and outputs just the file
names that differ. Output format is similar to "fossil changes".
But unlike "fossil changes" "fossil diff -q" can take --from and --to
options and, thus, compare arbitrary commits.
Affects of -q/--brief are limited to the internal diff implementation
and is noop if external diff is used.
The patch is against the trunk [b1530c29ab].
Thanks,
--Leo--
#### Fossil-SCM patch against trunk commit:
artifact: b1530c29ab659a56f488e4386f242eb758858f22
tags: trunk
type: Check-in by drh on 2012-02-07 04:15:41
comment: Add chunk number fragment marks to HTML diff output.
####
Index: src/diffcmd.c
==================================================================
--- src/diffcmd.c~0 2012-02-07 07:49:53.000000000 -0500
+++ src/diffcmd.c 2012-02-07 07:32:34.000000000 -0500
@@ -19,15 +19,27 @@
*/
#include "config.h"
#include "diffcmd.h"
#include <assert.h>
+/* Flag to supress diff output if -q or --brief option is given
+ * to the internal diff command
+ */
+static int hasQFlag = 0;
+
/*
** Print the "Index:" message that patches wants to see at the top of a diff.
+** If -q/--brief then print CHANGED instead.
*/
void diff_print_index(const char *zFile, int diffFlags){
- if( (diffFlags & DIFF_SIDEBYSIDE)==0 ){
+ if( (diffFlags & DIFF_SIDEBYSIDE) ){
+ return;
+ } else if( hasQFlag ){
+ char *z = mprintf("CHANGED %s\n", zFile);
+ fossil_print("%s", z);
+ fossil_free(z);
+ } else {
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
fossil_print("%s", z);
fossil_free(z);
}
}
@@ -35,10 +47,12 @@ void diff_print_index(const char *zFile,
/*
** Print the +++/--- filename lines for a diff operation.
*/
void diff_print_filenames(const char *zLeft, const char *zRight, int diffFlags){
char *z = 0;
+ if( hasQFlag ){ return; } /* don't print anything in -q/--brief mode */
+
if( diffFlags & DIFF_SIDEBYSIDE ){
int w = diff_width(diffFlags);
int n1 = strlen(zLeft);
int x;
if( n1>w*2 ) n1 = w*2;
@@ -89,11 +103,11 @@ void diff_file(
/* Compute and output the differences */
blob_zero(&out);
text_diff(pFile1, &file2, &out, diffFlags);
if( blob_size(&out) ){
diff_print_filenames(zName, zName2, diffFlags);
- fossil_print("%s\n", blob_str(&out));
+ if( !hasQFlag ){ fossil_print("%s\n", blob_str(&out)); }
}
/* Release memory resources */
blob_reset(&file2);
blob_reset(&out);
@@ -148,11 +162,11 @@ void diff_file_mem(
Blob out; /* Diff output text */
blob_zero(&out);
text_diff(pFile1, pFile2, &out, diffFlags);
diff_print_filenames(zName, zName, diffFlags);
- fossil_print("%s\n", blob_str(&out));
+ if( !hasQFlag ){ fossil_print("%s\n", blob_str(&out)); }
/* Release memory resources */
blob_reset(&out);
}else{
Blob cmd;
@@ -199,10 +213,11 @@ static void diff_one_against_disk(
historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
if( !isLink != !file_wd_islink(zFrom) ){
fossil_print("cannot compute difference between "
"symlink and regular file\n");
}else{
+ diff_print_index(zFileTreeName, diffFlags);
diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, diffFlags);
}
blob_reset(&content);
blob_reset(&fname);
}
@@ -283,11 +298,11 @@ static void diff_all_against_disk(
}else if( isNew ){
fossil_print("ADDED %s\n", zPathname);
srcid = 0;
if( !asNewFile ){ showDiff = 0; }
}else if( isChnged==3 ){
- fossil_print("ADDED_BY_MERGE %s\n", zPathname);
+ fossil_print("ADDED_BY_MERGE %s\n", zPathname);
srcid = 0;
if( !asNewFile ){ showDiff = 0; }
}
if( showDiff ){
Blob content;
@@ -403,27 +418,27 @@ static void diff_all_two_versions(
cmp = -1;
}else{
cmp = fossil_strcmp(pFromFile->zName, pToFile->zName);
}
if( cmp<0 ){
- fossil_print("DELETED %s\n", pFromFile->zName);
+ fossil_print("DELETED %s\n", pFromFile->zName);
if( asNewFlag ){
diff_manifest_entry(pFromFile, 0, zDiffCmd, diffFlags);
}
pFromFile = manifest_file_next(pFrom,0);
}else if( cmp>0 ){
- fossil_print("ADDED %s\n", pToFile->zName);
+ fossil_print("ADDED %s\n", pToFile->zName);
if( asNewFlag ){
diff_manifest_entry(0, pToFile, zDiffCmd, diffFlags);
}
pToFile = manifest_file_next(pTo,0);
}else if( fossil_strcmp(pFromFile->zUuid, pToFile->zUuid)==0 ){
/* No changes */
pFromFile = manifest_file_next(pFrom,0);
pToFile = manifest_file_next(pTo,0);
}else{
- /* fossil_print("CHANGED %s\n", pFromFile->zName); */
+ /* fossil_print("CHANGED %s\n", pFromFile->zName); */
diff_manifest_entry(pFromFile, pToFile, zDiffCmd, diffFlags);
pFromFile = manifest_file_next(pFrom,0);
pToFile = manifest_file_next(pTo,0);
}
}
@@ -461,10 +476,11 @@ static void diff_all_two_versions(
**
** Options:
** --context|-c N Use N lines of context
** --from|-r VERSION select VERSION as source for the diff
** --new-file|-N output complete text of added or deleted files
+** --brief|-q when using internal diff suppress diff output
** -i use internal diff logic
** --to VERSION select VERSION as target for the diff
** --side-by-side|-y side-by-side diff
** --width|-W N Width of lines in side-by-side diff
*/
@@ -482,10 +498,11 @@ void diff_cmd(void){
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;
+ hasQFlag = find_option("brief" ,"q",0)!=0;
if( hasNFlag ) diffFlags |= DIFF_NEWFILE;
if( zTo==0 ){
db_must_be_within_tree();
verify_all_options();
#EoF
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users