changeset 31272:e41946f39724

mdiff: extract a checknonewline inner function in unidiff()
author Denis Laxalde <denis.laxalde@logilab.fr>
date Fri, 03 Mar 2017 17:46:28 +0100
parents b3861be6aa6c
children 92714858dd3e
files mercurial/mdiff.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mdiff.py	Fri Mar 03 13:51:22 2017 +0100
+++ b/mercurial/mdiff.py	Fri Mar 03 17:46:28 2017 +0100
@@ -225,6 +225,12 @@
     fn1 = util.pconvert(fn1)
     fn2 = util.pconvert(fn2)
 
+    def checknonewline(lines):
+        for text in lines:
+            if text[-1] != '\n':
+                text += "\n\ No newline at end of file\n"
+            yield text
+
     if not opts.text and (util.binary(a) or util.binary(b)):
         if a and b and len(a) == len(b) and a == b:
             return sentinel
@@ -258,11 +264,7 @@
             "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)),
         ]
 
-    for ln in xrange(len(l)):
-        if l[ln][-1] != '\n':
-            l[ln] += "\n\ No newline at end of file\n"
-
-    return headerlines, "".join(l)
+    return headerlines, "".join(checknonewline(l))
 
 def _unidiff(t1, t2, opts=defaultopts):
     """Yield hunks of a headerless unified diff from t1 and t2 texts.