diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -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 = [ diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -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. diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -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, l """ 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) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2282,6 +2282,7 @@ def difffeatureopts(ui, opts=None, untru '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') diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -218,10 +218,10 @@ Show an error if we use --options with a 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 diff --git a/tests/test-diff-ignore-whitespace.t b/tests/test-diff-ignore-whitespace.t --- a/tests/test-diff-ignore-whitespace.t +++ b/tests/test-diff-ignore-whitespace.t @@ -407,8 +407,23 @@ Test \r (carriage return) as used in "DO +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 diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -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 diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t --- a/tests/test-qrecord.t +++ b/tests/test-qrecord.t @@ -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) diff --git a/tests/test-record.t b/tests/test-record.t --- a/tests/test-record.t +++ b/tests/test-record.t @@ -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)