diff --git a/eden/scm/sapling/patch.py b/eden/scm/sapling/patch.py index 526f7daf36c90..602e73996a619 100644 --- a/eden/scm/sapling/patch.py +++ b/eden/scm/sapling/patch.py @@ -2888,16 +2888,19 @@ def diffsinglehunkinline(hunklines): (b"+", "diff.inserted", btokens), ]: isprevnewline = True - for changed, token in tokens: + length = len(tokens) + for i, (changed, token) in enumerate(tokens): if isprevnewline: yield (prefix, label) isprevnewline = False # special handling line end + isnextnewline = i + 1 < length and tokens[i + 1][1] == b"\n" isendofline = token.endswith(b"\n") - if isendofline: - chomp = token[:-1] # chomp + if isendofline or isnextnewline: + chomp = token[:-1] if isendofline else token # chomp token = chomp.rstrip() # detect spaces at the end endspaces = chomp[len(token) :] + # scan tabs for maybetab in tabsplitter.findall(token): if b"\t" == maybetab[0:1]: @@ -2908,11 +2911,13 @@ def diffsinglehunkinline(hunklines): else: currentlabel = label + ".unchanged" yield (maybetab, currentlabel) - if isendofline: + + if isendofline or isnextnewline: if endspaces: yield (endspaces, "diff.trailingwhitespace") - yield (b"\n", "") - isprevnewline = True + if isendofline: + yield (b"\n", "") + isprevnewline = True def difflabel(func, *args, **kw): diff --git a/eden/scm/tests/test-diff-color.t b/eden/scm/tests/test-diff-color.t index cca7b14bdd864..9af0bbb8496b8 100644 --- a/eden/scm/tests/test-diff-color.t +++ b/eden/scm/tests/test-diff-color.t @@ -282,7 +282,7 @@ test trailing spaces color diff > this is the first line > this is the second line > EOF -tofix: the second line should end with diff.trailingwhitespace +the second line should end with diff.trailingwhitespace $ hg diff --config experimental.worddiff=True --color=debug [diff.diffline|diff --git a/file1 b/file1] [diff.file_a|--- a/file1] @@ -290,4 +290,4 @@ tofix: the second line should end with diff.trailingwhitespace [diff.hunk|@@ -1,2 +1,2 @@] this is the first line [diff.deleted|-][diff.deleted.unchanged|this is the second line] - [diff.inserted|+][diff.inserted.unchanged|this is the second line][diff.inserted.changed| ] + [diff.inserted|+][diff.inserted.unchanged|this is the second line][diff.trailingwhitespace| ]