comparison mercurial/mdiff.py @ 4878:372d93f03d3a

diff: correctly handle combinations of whitespace options
author Matt Mackall <mpm@selenic.com>
date Sat, 14 Jul 2007 12:44:47 -0500
parents 826659bd8053
children 7530334bf301
comparison
equal deleted inserted replaced
4877:242026115e6a 4878:372d93f03d3a
46 if v is None: 46 if v is None:
47 v = self.defaults[k] 47 v = self.defaults[k]
48 setattr(self, k, v) 48 setattr(self, k, v)
49 49
50 defaultopts = diffopts() 50 defaultopts = diffopts()
51
52 def wsclean(opts, text):
53 if opts.ignorews:
54 text = re.sub('[ \t]+', '', text)
55 elif opts.ignorewsamount:
56 text = re.sub('[ \t]+', ' ', text)
57 text = re.sub('[ \t]+\n', '\n', text)
58 if opts.ignoreblanklines:
59 text = re.sub('\n+', '', text)
60 return text
51 61
52 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts): 62 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
53 def datetag(date, addtab=True): 63 def datetag(date, addtab=True):
54 if not opts.git and not opts.nodates: 64 if not opts.git and not opts.nodates:
55 return '\t%s\n' % date 65 return '\t%s\n' % date
149 159
150 header = [ "--- %s\t\n" % header1, "+++ %s\t\n" % header2 ] 160 header = [ "--- %s\t\n" % header1, "+++ %s\t\n" % header2 ]
151 161
152 if opts.showfunc: 162 if opts.showfunc:
153 funcre = re.compile('\w') 163 funcre = re.compile('\w')
154 if opts.ignorewsamount:
155 wsamountre = re.compile('[ \t]+')
156 wsappendedre = re.compile(' \n')
157 if opts.ignoreblanklines:
158 wsblanklinesre = re.compile('\n')
159 if opts.ignorews:
160 wsre = re.compile('[ \t]')
161 164
162 # bdiff.blocks gives us the matching sequences in the files. The loop 165 # bdiff.blocks gives us the matching sequences in the files. The loop
163 # below finds the spaces between those matching sequences and translates 166 # below finds the spaces between those matching sequences and translates
164 # them into diff output. 167 # them into diff output.
165 # 168 #
187 # bdiff sometimes gives huge matches past eof, this check eats them, 190 # bdiff sometimes gives huge matches past eof, this check eats them,
188 # and deals with the special first match case described above 191 # and deals with the special first match case described above
189 if not old and not new: 192 if not old and not new:
190 continue 193 continue
191 194
192 if opts.ignoreblanklines: 195 if opts.ignorews or opts.ignorewsamount or opts.ignoreblanklines:
193 wsold = wsblanklinesre.sub('', "".join(old)) 196 if wsclean(opts, "".join(old)) == wsclean(opts, "".join(new)):
194 wsnew = wsblanklinesre.sub('', "".join(new))
195 if wsold == wsnew:
196 continue
197
198 if opts.ignorewsamount:
199 wsold = wsamountre.sub(' ', "".join(old))
200 wsold = wsappendedre.sub('\n', wsold)
201 wsnew = wsamountre.sub(' ', "".join(new))
202 wsnew = wsappendedre.sub('\n', wsnew)
203 if wsold == wsnew:
204 continue
205
206 if opts.ignorews:
207 wsold = wsre.sub('', "".join(old))
208 wsnew = wsre.sub('', "".join(new))
209 if wsold == wsnew:
210 continue 197 continue
211 198
212 astart = contextstart(a1) 199 astart = contextstart(a1)
213 bstart = contextstart(b1) 200 bstart = contextstart(b1)
214 prev = None 201 prev = None