##// END OF EJS Templates
diff: add -b/-B options
Haakon Riiser -
r2580:a20a1bb0 default
parent child Browse files
Show More
@@ -405,23 +405,33 b' def dodiff(fp, ui, repo, node1, node2, f'
405 diffopts = ui.diffopts()
405 diffopts = ui.diffopts()
406 showfunc = opts.get('show_function') or diffopts['showfunc']
406 showfunc = opts.get('show_function') or diffopts['showfunc']
407 ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
407 ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
408 ignorewsamount = opts.get('ignore_space_change') or \
409 diffopts['ignorewsamount']
410 ignoreblanklines = opts.get('ignore_blank_lines') or \
411 diffopts['ignoreblanklines']
408 for f in modified:
412 for f in modified:
409 to = None
413 to = None
410 if f in mmap:
414 if f in mmap:
411 to = repo.file(f).read(mmap[f])
415 to = repo.file(f).read(mmap[f])
412 tn = read(f)
416 tn = read(f)
413 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
417 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
414 showfunc=showfunc, ignorews=ignorews))
418 showfunc=showfunc, ignorews=ignorews,
419 ignorewsamount=ignorewsamount,
420 ignoreblanklines=ignoreblanklines))
415 for f in added:
421 for f in added:
416 to = None
422 to = None
417 tn = read(f)
423 tn = read(f)
418 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
424 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
419 showfunc=showfunc, ignorews=ignorews))
425 showfunc=showfunc, ignorews=ignorews,
426 ignorewsamount=ignorewsamount,
427 ignoreblanklines=ignoreblanklines))
420 for f in removed:
428 for f in removed:
421 to = repo.file(f).read(mmap[f])
429 to = repo.file(f).read(mmap[f])
422 tn = None
430 tn = None
423 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
431 fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
424 showfunc=showfunc, ignorews=ignorews))
432 showfunc=showfunc, ignorews=ignorews,
433 ignorewsamount=ignorewsamount,
434 ignoreblanklines=ignoreblanklines))
425
435
426 def trimuser(ui, name, rev, revcache):
436 def trimuser(ui, name, rev, revcache):
427 """trim the name of the user who committed a change"""
437 """trim the name of the user who committed a change"""
@@ -3018,6 +3028,10 b' table = {'
3018 _('show which function each change is in')),
3028 _('show which function each change is in')),
3019 ('w', 'ignore-all-space', None,
3029 ('w', 'ignore-all-space', None,
3020 _('ignore white space when comparing lines')),
3030 _('ignore white space when comparing lines')),
3031 ('b', 'ignore-space-change', None,
3032 _('ignore changes in the amount of white space')),
3033 ('B', 'ignore-blank-lines', None,
3034 _('ignore changes whose lines are all blank')),
3021 ('I', 'include', [], _('include names matching the given patterns')),
3035 ('I', 'include', [], _('include names matching the given patterns')),
3022 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3036 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3023 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
3037 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
@@ -133,21 +133,29 b' class hgweb(object):'
133 diffopts = self.repo.ui.diffopts()
133 diffopts = self.repo.ui.diffopts()
134 showfunc = diffopts['showfunc']
134 showfunc = diffopts['showfunc']
135 ignorews = diffopts['ignorews']
135 ignorews = diffopts['ignorews']
136 ignorewsamount = diffopts['ignorewsamount']
137 ignoreblanklines = diffopts['ignoreblanklines']
136 for f in modified:
138 for f in modified:
137 to = r.file(f).read(mmap1[f])
139 to = r.file(f).read(mmap1[f])
138 tn = r.file(f).read(mmap2[f])
140 tn = r.file(f).read(mmap2[f])
139 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
141 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
140 showfunc=showfunc, ignorews=ignorews), f, tn)
142 showfunc=showfunc, ignorews=ignorews,
143 ignorewsamount=ignorewsamount,
144 ignoreblanklines=ignoreblanklines), f, tn)
141 for f in added:
145 for f in added:
142 to = None
146 to = None
143 tn = r.file(f).read(mmap2[f])
147 tn = r.file(f).read(mmap2[f])
144 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
148 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
145 showfunc=showfunc, ignorews=ignorews), f, tn)
149 showfunc=showfunc, ignorews=ignorews,
150 ignorewsamount=ignorewsamount,
151 ignoreblanklines=ignoreblanklines), f, tn)
146 for f in removed:
152 for f in removed:
147 to = r.file(f).read(mmap1[f])
153 to = r.file(f).read(mmap1[f])
148 tn = None
154 tn = None
149 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
155 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
150 showfunc=showfunc, ignorews=ignorews), f, tn)
156 showfunc=showfunc, ignorews=ignorews,
157 ignorewsamount=ignorewsamount,
158 ignoreblanklines=ignoreblanklines), f, tn)
151
159
152 def changelog(self, pos):
160 def changelog(self, pos):
153 def changenav(**map):
161 def changenav(**map):
@@ -20,7 +20,8 b' def splitnewlines(text):'
20 return lines
20 return lines
21
21
22 def unidiff(a, ad, b, bd, fn, r=None, text=False,
22 def unidiff(a, ad, b, bd, fn, r=None, text=False,
23 showfunc=False, ignorews=False):
23 showfunc=False, ignorews=False, ignorewsamount=False,
24 ignoreblanklines=False):
24
25
25 if not a and not b: return ""
26 if not a and not b: return ""
26 epoch = util.datestr((0, 0))
27 epoch = util.datestr((0, 0))
@@ -49,7 +50,9 b' def unidiff(a, ad, b, bd, fn, r=None, te'
49 al = splitnewlines(a)
50 al = splitnewlines(a)
50 bl = splitnewlines(b)
51 bl = splitnewlines(b)
51 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
52 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
52 showfunc=showfunc, ignorews=ignorews))
53 showfunc=showfunc, ignorews=ignorews,
54 ignorewsamount=ignorewsamount,
55 ignoreblanklines=ignoreblanklines))
53 if not l: return ""
56 if not l: return ""
54 # difflib uses a space, rather than a tab
57 # difflib uses a space, rather than a tab
55 l[0] = "%s\t%s\n" % (l[0][:-2], ad)
58 l[0] = "%s\t%s\n" % (l[0][:-2], ad)
@@ -72,8 +75,10 b' def unidiff(a, ad, b, bd, fn, r=None, te'
72 # context is the number of context lines
75 # context is the number of context lines
73 # showfunc enables diff -p output
76 # showfunc enables diff -p output
74 # ignorews ignores all whitespace changes in the diff
77 # ignorews ignores all whitespace changes in the diff
78 # ignorewsamount ignores changes in the amount of whitespace
79 # ignoreblanklines ignores changes whose lines are all blank
75 def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
80 def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
76 ignorews=False):
81 ignorews=False, ignorewsamount=False, ignoreblanklines=False):
77 def contextend(l, len):
82 def contextend(l, len):
78 ret = l + context
83 ret = l + context
79 if ret > len:
84 if ret > len:
@@ -116,6 +121,11 b' def bunidiff(t1, t2, l1, l2, header1, he'
116
121
117 if showfunc:
122 if showfunc:
118 funcre = re.compile('\w')
123 funcre = re.compile('\w')
124 if ignorewsamount:
125 wsamountre = re.compile('[ \t]+')
126 wsappendedre = re.compile(' \n')
127 if ignoreblanklines:
128 wsblanklinesre = re.compile('\n')
119 if ignorews:
129 if ignorews:
120 wsre = re.compile('[ \t]')
130 wsre = re.compile('[ \t]')
121
131
@@ -149,6 +159,20 b' def bunidiff(t1, t2, l1, l2, header1, he'
149 if not old and not new:
159 if not old and not new:
150 continue
160 continue
151
161
162 if ignoreblanklines:
163 wsold = wsblanklinesre.sub('', "".join(old))
164 wsnew = wsblanklinesre.sub('', "".join(new))
165 if wsold == wsnew:
166 continue
167
168 if ignorewsamount:
169 wsold = wsamountre.sub(' ', "".join(old))
170 wsold = wsappendedre.sub('\n', wsold)
171 wsnew = wsamountre.sub(' ', "".join(new))
172 wsnew = wsappendedre.sub('\n', wsnew)
173 if wsold == wsnew:
174 continue
175
152 if ignorews:
176 if ignorews:
153 wsold = wsre.sub('', "".join(old))
177 wsold = wsre.sub('', "".join(old))
154 wsnew = wsre.sub('', "".join(new))
178 wsnew = wsre.sub('', "".join(new))
@@ -172,7 +172,8 b' class ui(object):'
172 def diffopts(self):
172 def diffopts(self):
173 if self.diffcache:
173 if self.diffcache:
174 return self.diffcache
174 return self.diffcache
175 result = {'showfunc': True, 'ignorews': False}
175 result = {'showfunc': True, 'ignorews': False,
176 'ignorewsamount': False, 'ignoreblanklines': False}
176 for key, value in self.configitems("diff"):
177 for key, value in self.configitems("diff"):
177 if value:
178 if value:
178 result[key.lower()] = (value.lower() == 'true')
179 result[key.lower()] = (value.lower() == 'true')
@@ -173,12 +173,14 b' diff repository (or selected files)'
173
173
174 options:
174 options:
175
175
176 -r --rev revision
176 -r --rev revision
177 -a --text treat all files as text
177 -a --text treat all files as text
178 -p --show-function show which function each change is in
178 -p --show-function show which function each change is in
179 -w --ignore-all-space ignore white space when comparing lines
179 -w --ignore-all-space ignore white space when comparing lines
180 -I --include include names matching the given patterns
180 -b --ignore-space-change ignore changes in the amount of white space
181 -X --exclude exclude names matching the given patterns
181 -B --ignore-blank-lines ignore changes whose lines are all blank
182 -I --include include names matching the given patterns
183 -X --exclude exclude names matching the given patterns
182 hg status [OPTION]... [FILE]...
184 hg status [OPTION]... [FILE]...
183
185
184 show changed files in the working directory
186 show changed files in the working directory
General Comments 0
You need to be logged in to leave comments. Login now