mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
diff: add -b/-B options
This commit is contained in:
parent
7dd019b60b
commit
7b06333d1a
@ -405,23 +405,33 @@ def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
|
|||||||
diffopts = ui.diffopts()
|
diffopts = ui.diffopts()
|
||||||
showfunc = opts.get('show_function') or diffopts['showfunc']
|
showfunc = opts.get('show_function') or diffopts['showfunc']
|
||||||
ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
|
ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
|
||||||
|
ignorewsamount = opts.get('ignore_space_change') or \
|
||||||
|
diffopts['ignorewsamount']
|
||||||
|
ignoreblanklines = opts.get('ignore_blank_lines') or \
|
||||||
|
diffopts['ignoreblanklines']
|
||||||
for f in modified:
|
for f in modified:
|
||||||
to = None
|
to = None
|
||||||
if f in mmap:
|
if f in mmap:
|
||||||
to = repo.file(f).read(mmap[f])
|
to = repo.file(f).read(mmap[f])
|
||||||
tn = read(f)
|
tn = read(f)
|
||||||
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
||||||
showfunc=showfunc, ignorews=ignorews))
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines))
|
||||||
for f in added:
|
for f in added:
|
||||||
to = None
|
to = None
|
||||||
tn = read(f)
|
tn = read(f)
|
||||||
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
||||||
showfunc=showfunc, ignorews=ignorews))
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines))
|
||||||
for f in removed:
|
for f in removed:
|
||||||
to = repo.file(f).read(mmap[f])
|
to = repo.file(f).read(mmap[f])
|
||||||
tn = None
|
tn = None
|
||||||
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
|
||||||
showfunc=showfunc, ignorews=ignorews))
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines))
|
||||||
|
|
||||||
def trimuser(ui, name, rev, revcache):
|
def trimuser(ui, name, rev, revcache):
|
||||||
"""trim the name of the user who committed a change"""
|
"""trim the name of the user who committed a change"""
|
||||||
@ -3018,6 +3028,10 @@ table = {
|
|||||||
_('show which function each change is in')),
|
_('show which function each change is in')),
|
||||||
('w', 'ignore-all-space', None,
|
('w', 'ignore-all-space', None,
|
||||||
_('ignore white space when comparing lines')),
|
_('ignore white space when comparing lines')),
|
||||||
|
('b', 'ignore-space-change', None,
|
||||||
|
_('ignore changes in the amount of white space')),
|
||||||
|
('B', 'ignore-blank-lines', None,
|
||||||
|
_('ignore changes whose lines are all blank')),
|
||||||
('I', 'include', [], _('include names matching the given patterns')),
|
('I', 'include', [], _('include names matching the given patterns')),
|
||||||
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
||||||
_('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
|
_('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
|
||||||
|
@ -133,21 +133,29 @@ class hgweb(object):
|
|||||||
diffopts = self.repo.ui.diffopts()
|
diffopts = self.repo.ui.diffopts()
|
||||||
showfunc = diffopts['showfunc']
|
showfunc = diffopts['showfunc']
|
||||||
ignorews = diffopts['ignorews']
|
ignorews = diffopts['ignorews']
|
||||||
|
ignorewsamount = diffopts['ignorewsamount']
|
||||||
|
ignoreblanklines = diffopts['ignoreblanklines']
|
||||||
for f in modified:
|
for f in modified:
|
||||||
to = r.file(f).read(mmap1[f])
|
to = r.file(f).read(mmap1[f])
|
||||||
tn = r.file(f).read(mmap2[f])
|
tn = r.file(f).read(mmap2[f])
|
||||||
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
||||||
showfunc=showfunc, ignorews=ignorews), f, tn)
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines), f, tn)
|
||||||
for f in added:
|
for f in added:
|
||||||
to = None
|
to = None
|
||||||
tn = r.file(f).read(mmap2[f])
|
tn = r.file(f).read(mmap2[f])
|
||||||
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
||||||
showfunc=showfunc, ignorews=ignorews), f, tn)
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines), f, tn)
|
||||||
for f in removed:
|
for f in removed:
|
||||||
to = r.file(f).read(mmap1[f])
|
to = r.file(f).read(mmap1[f])
|
||||||
tn = None
|
tn = None
|
||||||
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
|
||||||
showfunc=showfunc, ignorews=ignorews), f, tn)
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines), f, tn)
|
||||||
|
|
||||||
def changelog(self, pos):
|
def changelog(self, pos):
|
||||||
def changenav(**map):
|
def changenav(**map):
|
||||||
|
@ -20,7 +20,8 @@ def splitnewlines(text):
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
def unidiff(a, ad, b, bd, fn, r=None, text=False,
|
def unidiff(a, ad, b, bd, fn, r=None, text=False,
|
||||||
showfunc=False, ignorews=False):
|
showfunc=False, ignorews=False, ignorewsamount=False,
|
||||||
|
ignoreblanklines=False):
|
||||||
|
|
||||||
if not a and not b: return ""
|
if not a and not b: return ""
|
||||||
epoch = util.datestr((0, 0))
|
epoch = util.datestr((0, 0))
|
||||||
@ -49,7 +50,9 @@ def unidiff(a, ad, b, bd, fn, r=None, text=False,
|
|||||||
al = splitnewlines(a)
|
al = splitnewlines(a)
|
||||||
bl = splitnewlines(b)
|
bl = splitnewlines(b)
|
||||||
l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
|
l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
|
||||||
showfunc=showfunc, ignorews=ignorews))
|
showfunc=showfunc, ignorews=ignorews,
|
||||||
|
ignorewsamount=ignorewsamount,
|
||||||
|
ignoreblanklines=ignoreblanklines))
|
||||||
if not l: return ""
|
if not l: return ""
|
||||||
# difflib uses a space, rather than a tab
|
# difflib uses a space, rather than a tab
|
||||||
l[0] = "%s\t%s\n" % (l[0][:-2], ad)
|
l[0] = "%s\t%s\n" % (l[0][:-2], ad)
|
||||||
@ -72,8 +75,10 @@ def unidiff(a, ad, b, bd, fn, r=None, text=False,
|
|||||||
# context is the number of context lines
|
# context is the number of context lines
|
||||||
# showfunc enables diff -p output
|
# showfunc enables diff -p output
|
||||||
# ignorews ignores all whitespace changes in the diff
|
# ignorews ignores all whitespace changes in the diff
|
||||||
|
# ignorewsamount ignores changes in the amount of whitespace
|
||||||
|
# ignoreblanklines ignores changes whose lines are all blank
|
||||||
def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
|
def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
|
||||||
ignorews=False):
|
ignorews=False, ignorewsamount=False, ignoreblanklines=False):
|
||||||
def contextend(l, len):
|
def contextend(l, len):
|
||||||
ret = l + context
|
ret = l + context
|
||||||
if ret > len:
|
if ret > len:
|
||||||
@ -116,6 +121,11 @@ def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
|
|||||||
|
|
||||||
if showfunc:
|
if showfunc:
|
||||||
funcre = re.compile('\w')
|
funcre = re.compile('\w')
|
||||||
|
if ignorewsamount:
|
||||||
|
wsamountre = re.compile('[ \t]+')
|
||||||
|
wsappendedre = re.compile(' \n')
|
||||||
|
if ignoreblanklines:
|
||||||
|
wsblanklinesre = re.compile('\n')
|
||||||
if ignorews:
|
if ignorews:
|
||||||
wsre = re.compile('[ \t]')
|
wsre = re.compile('[ \t]')
|
||||||
|
|
||||||
@ -149,6 +159,20 @@ def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
|
|||||||
if not old and not new:
|
if not old and not new:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if ignoreblanklines:
|
||||||
|
wsold = wsblanklinesre.sub('', "".join(old))
|
||||||
|
wsnew = wsblanklinesre.sub('', "".join(new))
|
||||||
|
if wsold == wsnew:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if ignorewsamount:
|
||||||
|
wsold = wsamountre.sub(' ', "".join(old))
|
||||||
|
wsold = wsappendedre.sub('\n', wsold)
|
||||||
|
wsnew = wsamountre.sub(' ', "".join(new))
|
||||||
|
wsnew = wsappendedre.sub('\n', wsnew)
|
||||||
|
if wsold == wsnew:
|
||||||
|
continue
|
||||||
|
|
||||||
if ignorews:
|
if ignorews:
|
||||||
wsold = wsre.sub('', "".join(old))
|
wsold = wsre.sub('', "".join(old))
|
||||||
wsnew = wsre.sub('', "".join(new))
|
wsnew = wsre.sub('', "".join(new))
|
||||||
|
@ -172,7 +172,8 @@ class ui(object):
|
|||||||
def diffopts(self):
|
def diffopts(self):
|
||||||
if self.diffcache:
|
if self.diffcache:
|
||||||
return self.diffcache
|
return self.diffcache
|
||||||
result = {'showfunc': True, 'ignorews': False}
|
result = {'showfunc': True, 'ignorews': False,
|
||||||
|
'ignorewsamount': False, 'ignoreblanklines': False}
|
||||||
for key, value in self.configitems("diff"):
|
for key, value in self.configitems("diff"):
|
||||||
if value:
|
if value:
|
||||||
result[key.lower()] = (value.lower() == 'true')
|
result[key.lower()] = (value.lower() == 'true')
|
||||||
|
@ -173,12 +173,14 @@ diff repository (or selected files)
|
|||||||
|
|
||||||
options:
|
options:
|
||||||
|
|
||||||
-r --rev revision
|
-r --rev revision
|
||||||
-a --text treat all files as text
|
-a --text treat all files as text
|
||||||
-p --show-function show which function each change is in
|
-p --show-function show which function each change is in
|
||||||
-w --ignore-all-space ignore white space when comparing lines
|
-w --ignore-all-space ignore white space when comparing lines
|
||||||
-I --include include names matching the given patterns
|
-b --ignore-space-change ignore changes in the amount of white space
|
||||||
-X --exclude exclude names matching the given patterns
|
-B --ignore-blank-lines ignore changes whose lines are all blank
|
||||||
|
-I --include include names matching the given patterns
|
||||||
|
-X --exclude exclude names matching the given patterns
|
||||||
hg status [OPTION]... [FILE]...
|
hg status [OPTION]... [FILE]...
|
||||||
|
|
||||||
show changed files in the working directory
|
show changed files in the working directory
|
||||||
|
Loading…
Reference in New Issue
Block a user