Fossil SCM

Add '--versions' option to 'fossil diff' to display details about the compared versions.

danield 2022-06-22 13:37 trunk merge
Commit 41f6a4519e07185722aaac0b32d0240cf401f42986c7968fe8599bd334caeca6
2 files changed +2 +39 -1
+2
--- src/diff.c
+++ src/diff.c
@@ -47,10 +47,11 @@
4747
#define DIFF_JSON 0x00010000 /* JSON output */
4848
#define DIFF_DEBUG 0x00020000 /* Debugging diff output */
4949
#define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
5050
#define DIFF_TCL 0x00080000 /* For the --tk option */
5151
#define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
52
+#define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */
5253
5354
/*
5455
** These error messages are shared in multiple locations. They are defined
5556
** here for consistency.
5657
*/
@@ -3161,10 +3162,11 @@
31613162
pCfg->wColumn = f;
31623163
}
31633164
if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
31643165
if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
31653166
if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT;
3167
+ if( find_option("versions","h",0)!=0 ) diffFlags |= DIFF_SHOW_VERS;
31663168
if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
31673169
if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
31683170
if( find_option("internal","i",0)==0
31693171
&& (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0
31703172
){
31713173
--- src/diff.c
+++ src/diff.c
@@ -47,10 +47,11 @@
47 #define DIFF_JSON 0x00010000 /* JSON output */
48 #define DIFF_DEBUG 0x00020000 /* Debugging diff output */
49 #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
50 #define DIFF_TCL 0x00080000 /* For the --tk option */
51 #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
 
52
53 /*
54 ** These error messages are shared in multiple locations. They are defined
55 ** here for consistency.
56 */
@@ -3161,10 +3162,11 @@
3161 pCfg->wColumn = f;
3162 }
3163 if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
3164 if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
3165 if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT;
 
3166 if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
3167 if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
3168 if( find_option("internal","i",0)==0
3169 && (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0
3170 ){
3171
--- src/diff.c
+++ src/diff.c
@@ -47,10 +47,11 @@
47 #define DIFF_JSON 0x00010000 /* JSON output */
48 #define DIFF_DEBUG 0x00020000 /* Debugging diff output */
49 #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
50 #define DIFF_TCL 0x00080000 /* For the --tk option */
51 #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
52 #define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */
53
54 /*
55 ** These error messages are shared in multiple locations. They are defined
56 ** here for consistency.
57 */
@@ -3161,10 +3162,11 @@
3162 pCfg->wColumn = f;
3163 }
3164 if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
3165 if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
3166 if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT;
3167 if( find_option("versions","h",0)!=0 ) diffFlags |= DIFF_SHOW_VERS;
3168 if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
3169 if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
3170 if( find_option("internal","i",0)==0
3171 && (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0
3172 ){
3173
+39 -1
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,10 +109,37 @@
109109
p->nUsed++;
110110
return 1;
111111
}
112112
return 0;
113113
}
114
+
115
+/*
116
+** Print details about the compared versions - possibly the working directory
117
+** or the undo buffer. For check-ins, show hash and commit time.
118
+**
119
+** This is intended primarily to go into the "header garbage" that is ignored
120
+** by patch(1).
121
+**
122
+** zFrom and zTo are interpreted as symbolic version names, unless they
123
+** start with '(', in which case they are printed directly.
124
+*/
125
+void diff_print_versions(const char *zFrom, const char *zTo, DiffConfig *pCfg){
126
+ if( (pCfg->diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|
127
+ DIFF_HTML|DIFF_WEBPAGE|DIFF_BROWSER|DIFF_JSON|DIFF_TCL))==0 ){
128
+ fossil_print("Fossil-Diff-From: %s\n",
129
+ zFrom[0]=='(' ? zFrom : mprintf("%S %s",
130
+ rid_to_uuid(symbolic_name_to_rid(zFrom, "ci")),
131
+ db_text("","SELECT datetime(%f)||' UTC'",
132
+ symbolic_name_to_mtime(zFrom, 0))));
133
+ fossil_print("Fossil-Diff-To: %s\n",
134
+ zTo[0]=='(' ? zTo : mprintf("%S %s",
135
+ rid_to_uuid(symbolic_name_to_rid(zTo, "ci")),
136
+ db_text("","SELECT datetime(%f)||' UTC'",
137
+ symbolic_name_to_mtime(zTo, 0))));
138
+ fossil_print("%.66c\n", '-');
139
+ }
140
+}
114141
115142
/*
116143
** Print the "Index:" message that patches wants to see at the top of a diff.
117144
*/
118145
void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){
@@ -125,10 +152,11 @@
125152
}
126153
127154
/*
128155
** Print the +++/--- filename lines or whatever filename information
129156
** is appropriate for the output format.
157
+**
130158
*/
131159
void diff_print_filenames(
132160
const char *zLeft, /* Name of the left file */
133161
const char *zRight, /* Name of the right file */
134162
DiffConfig *pCfg, /* Diff configuration */
@@ -659,10 +687,14 @@
659687
" WHERE vid=%d"
660688
" AND (deleted OR chnged OR rid==0)"
661689
" ORDER BY pathname /*scan*/",
662690
vid
663691
);
692
+ }
693
+ if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
694
+ diff_print_versions(zFrom ? zFrom : db_lget("checkout-hash", 0),
695
+ "(workdir)", pCfg);
664696
}
665697
db_prepare(&q, "%s", blob_sql_text(&sql));
666698
blob_reset(&sql);
667699
while( db_step(&q)==SQLITE_ROW ){
668700
const char *zPathname = db_column_text(&q,0);
@@ -744,10 +776,13 @@
744776
){
745777
Stmt q;
746778
Blob content;
747779
db_prepare(&q, "SELECT pathname, content FROM undo");
748780
blob_init(&content, 0, 0);
781
+ if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
782
+ diff_print_versions("(undo)", "(workdir)", pCfg);
783
+ }
749784
while( db_step(&q)==SQLITE_ROW ){
750785
char *zFullName;
751786
const char *zFile = (const char*)db_column_text(&q, 0);
752787
if( !file_dir_match(pFileDir, zFile) ) continue;
753788
zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
@@ -828,11 +863,13 @@
828863
manifest_file_rewind(pFrom);
829864
pFromFile = manifest_file_next(pFrom,0);
830865
pTo = manifest_get_by_name(zTo, 0);
831866
manifest_file_rewind(pTo);
832867
pToFile = manifest_file_next(pTo,0);
833
-
868
+ if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
869
+ diff_print_versions(zFrom, zTo, pCfg);
870
+ }
834871
while( pFromFile || pToFile ){
835872
int cmp;
836873
if( pFromFile==0 ){
837874
cmp = +1;
838875
}else if( pToFile==0 ){
@@ -1058,10 +1095,11 @@
10581095
** --tk Launch a Tcl/Tk GUI for display
10591096
** --to VERSION Select VERSION as target for the diff
10601097
** --undo Diff against the "undo" buffer
10611098
** --unified Unified diff
10621099
** -v|--verbose Output complete text of added or deleted files
1100
+** -h|--versions Show compared versions in the diff header
10631101
** --webpage Format output as a stand-alone HTML webpage
10641102
** -W|--width N Width of lines in side-by-side diff
10651103
** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace
10661104
*/
10671105
void diff_cmd(void){
10681106
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,10 +109,37 @@
109 p->nUsed++;
110 return 1;
111 }
112 return 0;
113 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
115 /*
116 ** Print the "Index:" message that patches wants to see at the top of a diff.
117 */
118 void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){
@@ -125,10 +152,11 @@
125 }
126
127 /*
128 ** Print the +++/--- filename lines or whatever filename information
129 ** is appropriate for the output format.
 
130 */
131 void diff_print_filenames(
132 const char *zLeft, /* Name of the left file */
133 const char *zRight, /* Name of the right file */
134 DiffConfig *pCfg, /* Diff configuration */
@@ -659,10 +687,14 @@
659 " WHERE vid=%d"
660 " AND (deleted OR chnged OR rid==0)"
661 " ORDER BY pathname /*scan*/",
662 vid
663 );
 
 
 
 
664 }
665 db_prepare(&q, "%s", blob_sql_text(&sql));
666 blob_reset(&sql);
667 while( db_step(&q)==SQLITE_ROW ){
668 const char *zPathname = db_column_text(&q,0);
@@ -744,10 +776,13 @@
744 ){
745 Stmt q;
746 Blob content;
747 db_prepare(&q, "SELECT pathname, content FROM undo");
748 blob_init(&content, 0, 0);
 
 
 
749 while( db_step(&q)==SQLITE_ROW ){
750 char *zFullName;
751 const char *zFile = (const char*)db_column_text(&q, 0);
752 if( !file_dir_match(pFileDir, zFile) ) continue;
753 zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
@@ -828,11 +863,13 @@
828 manifest_file_rewind(pFrom);
829 pFromFile = manifest_file_next(pFrom,0);
830 pTo = manifest_get_by_name(zTo, 0);
831 manifest_file_rewind(pTo);
832 pToFile = manifest_file_next(pTo,0);
833
 
 
834 while( pFromFile || pToFile ){
835 int cmp;
836 if( pFromFile==0 ){
837 cmp = +1;
838 }else if( pToFile==0 ){
@@ -1058,10 +1095,11 @@
1058 ** --tk Launch a Tcl/Tk GUI for display
1059 ** --to VERSION Select VERSION as target for the diff
1060 ** --undo Diff against the "undo" buffer
1061 ** --unified Unified diff
1062 ** -v|--verbose Output complete text of added or deleted files
 
1063 ** --webpage Format output as a stand-alone HTML webpage
1064 ** -W|--width N Width of lines in side-by-side diff
1065 ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace
1066 */
1067 void diff_cmd(void){
1068
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,10 +109,37 @@
109 p->nUsed++;
110 return 1;
111 }
112 return 0;
113 }
114
115 /*
116 ** Print details about the compared versions - possibly the working directory
117 ** or the undo buffer. For check-ins, show hash and commit time.
118 **
119 ** This is intended primarily to go into the "header garbage" that is ignored
120 ** by patch(1).
121 **
122 ** zFrom and zTo are interpreted as symbolic version names, unless they
123 ** start with '(', in which case they are printed directly.
124 */
125 void diff_print_versions(const char *zFrom, const char *zTo, DiffConfig *pCfg){
126 if( (pCfg->diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|
127 DIFF_HTML|DIFF_WEBPAGE|DIFF_BROWSER|DIFF_JSON|DIFF_TCL))==0 ){
128 fossil_print("Fossil-Diff-From: %s\n",
129 zFrom[0]=='(' ? zFrom : mprintf("%S %s",
130 rid_to_uuid(symbolic_name_to_rid(zFrom, "ci")),
131 db_text("","SELECT datetime(%f)||' UTC'",
132 symbolic_name_to_mtime(zFrom, 0))));
133 fossil_print("Fossil-Diff-To: %s\n",
134 zTo[0]=='(' ? zTo : mprintf("%S %s",
135 rid_to_uuid(symbolic_name_to_rid(zTo, "ci")),
136 db_text("","SELECT datetime(%f)||' UTC'",
137 symbolic_name_to_mtime(zTo, 0))));
138 fossil_print("%.66c\n", '-');
139 }
140 }
141
142 /*
143 ** Print the "Index:" message that patches wants to see at the top of a diff.
144 */
145 void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){
@@ -125,10 +152,11 @@
152 }
153
154 /*
155 ** Print the +++/--- filename lines or whatever filename information
156 ** is appropriate for the output format.
157 **
158 */
159 void diff_print_filenames(
160 const char *zLeft, /* Name of the left file */
161 const char *zRight, /* Name of the right file */
162 DiffConfig *pCfg, /* Diff configuration */
@@ -659,10 +687,14 @@
687 " WHERE vid=%d"
688 " AND (deleted OR chnged OR rid==0)"
689 " ORDER BY pathname /*scan*/",
690 vid
691 );
692 }
693 if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
694 diff_print_versions(zFrom ? zFrom : db_lget("checkout-hash", 0),
695 "(workdir)", pCfg);
696 }
697 db_prepare(&q, "%s", blob_sql_text(&sql));
698 blob_reset(&sql);
699 while( db_step(&q)==SQLITE_ROW ){
700 const char *zPathname = db_column_text(&q,0);
@@ -744,10 +776,13 @@
776 ){
777 Stmt q;
778 Blob content;
779 db_prepare(&q, "SELECT pathname, content FROM undo");
780 blob_init(&content, 0, 0);
781 if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
782 diff_print_versions("(undo)", "(workdir)", pCfg);
783 }
784 while( db_step(&q)==SQLITE_ROW ){
785 char *zFullName;
786 const char *zFile = (const char*)db_column_text(&q, 0);
787 if( !file_dir_match(pFileDir, zFile) ) continue;
788 zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
@@ -828,11 +863,13 @@
863 manifest_file_rewind(pFrom);
864 pFromFile = manifest_file_next(pFrom,0);
865 pTo = manifest_get_by_name(zTo, 0);
866 manifest_file_rewind(pTo);
867 pToFile = manifest_file_next(pTo,0);
868 if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){
869 diff_print_versions(zFrom, zTo, pCfg);
870 }
871 while( pFromFile || pToFile ){
872 int cmp;
873 if( pFromFile==0 ){
874 cmp = +1;
875 }else if( pToFile==0 ){
@@ -1058,10 +1095,11 @@
1095 ** --tk Launch a Tcl/Tk GUI for display
1096 ** --to VERSION Select VERSION as target for the diff
1097 ** --undo Diff against the "undo" buffer
1098 ** --unified Unified diff
1099 ** -v|--verbose Output complete text of added or deleted files
1100 ** -h|--versions Show compared versions in the diff header
1101 ** --webpage Format output as a stand-alone HTML webpage
1102 ** -W|--width N Width of lines in side-by-side diff
1103 ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace
1104 */
1105 void diff_cmd(void){
1106

Keyboard Shortcuts

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