5
5
#include "diffcore.h"
6
6
#include "quote.h"
7
7
#include "xdiff-interface.h"
8
+ #include "xdiff/xmacros.h"
8
9
#include "log-tree.h"
9
10
#include "refs.h"
10
11
#include "userdiff.h"
@@ -122,7 +123,47 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
122
123
return blob ;
123
124
}
124
125
125
- static void append_lost (struct sline * sline , int n , const char * line , int len )
126
+ static int match_string_spaces (const char * line1 , int len1 ,
127
+ const char * line2 , int len2 ,
128
+ long flags )
129
+ {
130
+ if (flags & XDF_WHITESPACE_FLAGS ) {
131
+ for (; len1 > 0 && XDL_ISSPACE (line1 [len1 - 1 ]); len1 -- );
132
+ for (; len2 > 0 && XDL_ISSPACE (line2 [len2 - 1 ]); len2 -- );
133
+ }
134
+
135
+ if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE )))
136
+ return (len1 == len2 && !memcmp (line1 , line2 , len1 ));
137
+
138
+ while (len1 > 0 && len2 > 0 ) {
139
+ len1 -- ;
140
+ len2 -- ;
141
+ if (XDL_ISSPACE (line1 [len1 ]) || XDL_ISSPACE (line2 [len2 ])) {
142
+ if ((flags & XDF_IGNORE_WHITESPACE_CHANGE ) &&
143
+ (!XDL_ISSPACE (line1 [len1 ]) || !XDL_ISSPACE (line2 [len2 ])))
144
+ return 0 ;
145
+
146
+ for (; len1 > 0 && XDL_ISSPACE (line1 [len1 ]); len1 -- );
147
+ for (; len2 > 0 && XDL_ISSPACE (line2 [len2 ]); len2 -- );
148
+ }
149
+ if (line1 [len1 ] != line2 [len2 ])
150
+ return 0 ;
151
+ }
152
+
153
+ if (flags & XDF_IGNORE_WHITESPACE ) {
154
+ /* Consume remaining spaces */
155
+ for (; len1 > 0 && XDL_ISSPACE (line1 [len1 - 1 ]); len1 -- );
156
+ for (; len2 > 0 && XDL_ISSPACE (line2 [len2 - 1 ]); len2 -- );
157
+ }
158
+
159
+ /* We matched full line1 and line2 */
160
+ if (!len1 && !len2 )
161
+ return 1 ;
162
+
163
+ return 0 ;
164
+ }
165
+
166
+ static void append_lost (struct sline * sline , int n , const char * line , int len , long flags )
126
167
{
127
168
struct lline * lline ;
128
169
unsigned long this_mask = (1UL <<n );
@@ -133,8 +174,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
133
174
if (sline -> lost_head ) {
134
175
lline = sline -> next_lost ;
135
176
while (lline ) {
136
- if (lline -> len == len &&
137
- ! memcmp ( lline -> line , line , len )) {
177
+ if (match_string_spaces ( lline -> line , lline -> len ,
178
+ line , len , flags )) {
138
179
lline -> parent_map |= this_mask ;
139
180
sline -> next_lost = lline -> next ;
140
181
return ;
@@ -162,6 +203,7 @@ struct combine_diff_state {
162
203
int n ;
163
204
struct sline * sline ;
164
205
struct sline * lost_bucket ;
206
+ long flags ;
165
207
};
166
208
167
209
static void consume_line (void * state_ , char * line , unsigned long len )
@@ -201,7 +243,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
201
243
return ; /* not in any hunk yet */
202
244
switch (line [0 ]) {
203
245
case '-' :
204
- append_lost (state -> lost_bucket , state -> n , line + 1 , len - 1 );
246
+ append_lost (state -> lost_bucket , state -> n , line + 1 , len - 1 , state -> flags );
205
247
break ;
206
248
case '+' :
207
249
state -> sline [state -> lno - 1 ].flag |= state -> nmask ;
@@ -215,7 +257,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
215
257
struct sline * sline , unsigned int cnt , int n ,
216
258
int num_parent , int result_deleted ,
217
259
struct userdiff_driver * textconv ,
218
- const char * path )
260
+ const char * path , long flags )
219
261
{
220
262
unsigned int p_lno , lno ;
221
263
unsigned long nmask = (1UL << n );
@@ -231,9 +273,10 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
231
273
parent_file .ptr = grab_blob (parent , mode , & sz , textconv , path );
232
274
parent_file .size = sz ;
233
275
memset (& xpp , 0 , sizeof (xpp ));
234
- xpp .flags = 0 ;
276
+ xpp .flags = flags ;
235
277
memset (& xecfg , 0 , sizeof (xecfg ));
236
278
memset (& state , 0 , sizeof (state ));
279
+ state .flags = flags ;
237
280
state .nmask = nmask ;
238
281
state .sline = sline ;
239
282
state .lno = 1 ;
@@ -962,7 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
962
1005
elem -> parent [i ].mode ,
963
1006
& result_file , sline ,
964
1007
cnt , i , num_parent , result_deleted ,
965
- textconv , elem -> path );
1008
+ textconv , elem -> path , opt -> xdl_opts );
966
1009
}
967
1010
968
1011
show_hunks = make_hunks (sline , cnt , num_parent , dense );
0 commit comments