mdiff: add a --ignore-space-at-eol option

Add an option that only ignores whitespaces at EOL. The name of the option is
the same as Git.

.. feature::

   Added `--ignore-space-at-eol` diff option to ignore whitespace differences
   at line endings.

Differential Revision: https://phab.mercurial-scm.org/D422
This commit is contained in:
David Soria Parra 2017-08-29 18:20:50 -07:00
parent a2849aacae
commit 6d9f90fa8d
9 changed files with 31 additions and 3 deletions

View File

@ -123,6 +123,8 @@ diffwsopts = [
_('ignore changes in the amount of white space')),
('B', 'ignore-blank-lines', None,
_('ignore changes whose lines are all blank')),
('Z', 'ignore-space-at-eol', None,
_('ignore changes in whitespace at EOL')),
]
diffopts2 = [

View File

@ -313,6 +313,9 @@ related options for the diff command.
``ignorews``
Ignore white space when comparing lines.
``ignorewseol``
Ignore white space at the end of a line when comparing lines.
``ignorewsamount``
Ignore changes in the amount of white space.

View File

@ -63,6 +63,7 @@ class diffopts(object):
'index': 0,
'ignorews': False,
'ignorewsamount': False,
'ignorewseol': False,
'ignoreblanklines': False,
'upgrade': False,
'showsimilarity': False,
@ -97,6 +98,8 @@ def wsclean(opts, text, blank=True):
text = bdiff.fixws(text, 0)
if blank and opts.ignoreblanklines:
text = re.sub('\n+', '\n', text).strip('\n')
if opts.ignorewseol:
text = re.sub(r'[ \t\r\f]+\n', r'\n', text)
return text
def splitblock(base1, lines1, base2, lines2, opts):
@ -199,7 +202,7 @@ def allblocks(text1, text2, opts=None, lines1=None, lines2=None):
"""
if opts is None:
opts = defaultopts
if opts.ignorews or opts.ignorewsamount:
if opts.ignorews or opts.ignorewsamount or opts.ignorewseol:
text1 = wsclean(opts, text1, False)
text2 = wsclean(opts, text2, False)
diff = bdiff.blocks(text1, text2)

View File

@ -2282,6 +2282,7 @@ def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False,
'ignorewsamount')
buildopts['ignoreblanklines'] = get('ignore_blank_lines',
'ignoreblanklines')
buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol')
if formatchanging:
buildopts['text'] = opts and opts.get('text')
binary = None if opts is None else opts.get('binary')

View File

@ -218,10 +218,10 @@ Show an error if we use --options with an ambiguous abbreviation
Show all commands + options
$ hg debugcommands
add: include, exclude, subrepos, dry-run
annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, skip, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude, template
annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, skip, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, include, exclude, template
clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, root, include, exclude, subrepos
diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos
export: output, switch-parent, rev, text, git, binary, nodates
forget: include, exclude
init: ssh, remotecmd, insecure

View File

@ -407,8 +407,23 @@ Test \r (carriage return) as used in "DOS" line endings:
+goodbye\r (no-eol) (esc)
world
Test \r (carriage return) as used in "DOS" line endings:
$ printf 'hello world \r\n\t\ngoodbye world\n' >foo
$ hg ndiff --ignore-space-at-eol
diff -r 540c40a65b78 foo
--- a/foo
+++ b/foo
@@ -1,2 +1,3 @@
hello world
+\t (esc)
goodbye world
No completely blank lines to ignore:
$ printf 'hello world\r\n\r\ngoodbye\rworld\n' >foo
$ hg ndiff --ignore-blank-lines
diff -r 540c40a65b78 foo
--- a/foo

View File

@ -553,6 +553,7 @@ Test command without options
-w --ignore-all-space ignore white space when comparing lines
-b --ignore-space-change ignore changes in the amount of white space
-B --ignore-blank-lines ignore changes whose lines are all blank
-Z --ignore-space-at-eol ignore changes in whitespace at EOL
-U --unified NUM number of lines of context to show
--stat output diffstat-style summary of changes
--root DIR produce diffs relative to subdirectory

View File

@ -79,6 +79,7 @@ help record (record)
-w --ignore-all-space ignore white space when comparing lines
-b --ignore-space-change ignore changes in the amount of white space
-B --ignore-blank-lines ignore changes whose lines are all blank
-Z --ignore-space-at-eol ignore changes in whitespace at EOL
(some details hidden, use --verbose to show complete help)
@ -152,6 +153,7 @@ help (mq present)
-w --ignore-all-space ignore white space when comparing lines
-b --ignore-space-change ignore changes in the amount of white space
-B --ignore-blank-lines ignore changes whose lines are all blank
-Z --ignore-space-at-eol ignore changes in whitespace at EOL
--mq operate on patch repository
(some details hidden, use --verbose to show complete help)

View File

@ -62,6 +62,7 @@ Record help
-w --ignore-all-space ignore white space when comparing lines
-b --ignore-space-change ignore changes in the amount of white space
-B --ignore-blank-lines ignore changes whose lines are all blank
-Z --ignore-space-at-eol ignore changes in whitespace at EOL
(some details hidden, use --verbose to show complete help)