Patchwork [06,of,10,RESEND] mdiff: extract a checknonewline inner function in unidiff()

login
register
mail settings
Submitter Denis Laxalde
Date March 9, 2017, 8:08 a.m.
Message ID <9cfb7ccf0a6f4f204348.1489046883@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/19057/
State Accepted
Headers show

Comments

Denis Laxalde - March 9, 2017, 8:08 a.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1488559588 -3600
#      Fri Mar 03 17:46:28 2017 +0100
# Node ID 9cfb7ccf0a6f4f204348165dbb204e740fa79616
# Parent  99f40e2d293c232cb8c9e1544128346493e542d2
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 9cfb7ccf0a6f
# EXP-Topic diffhunks
mdiff: extract a checknonewline inner function in unidiff()

Patch

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -225,6 +225,12 @@  def unidiff(a, ad, b, bd, fn1, fn2, opts
     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 @@  def unidiff(a, ad, b, bd, fn1, fn2, opts
             "+++ %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.