Patchwork [01,of,10,RESEND] mdiff: compute newlines-splitted texts within _unidiff

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

Comments

Denis Laxalde - March 9, 2017, 8:07 a.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1475000855 -7200
#      Tue Sep 27 20:27:35 2016 +0200
# Node ID 11b33e205503eb0d7911130d4579e04e7429e8f6
# Parent  150cd51257221fad5ccba5794e7a21837afba479
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 11b33e205503
# EXP-Topic diffhunks
mdiff: compute newlines-splitted texts within _unidiff

There is no reason to compute splitted texts l1, l2 in unidiff() before
calling _unidiff as they are only used with the latter function.

Patch

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -240,9 +240,7 @@  def unidiff(a, ad, b, bd, fn1, fn2, opts
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)
         l = [l1, l2, l3] + ["-" + e for e in a]
     else:
-        al = splitnewlines(a)
-        bl = splitnewlines(b)
-        l = list(_unidiff(a, b, al, bl, opts=opts))
+        l = list(_unidiff(a, b, opts=opts))
         if not l:
             return ""
 
@@ -257,8 +255,9 @@  def unidiff(a, ad, b, bd, fn1, fn2, opts
 
 # creates a headerless unified diff
 # t1 and t2 are the text to be diffed
-# l1 and l2 are the text broken up into lines
-def _unidiff(t1, t2, l1, l2, opts=defaultopts):
+def _unidiff(t1, t2, opts=defaultopts):
+    l1 = splitnewlines(t1)
+    l2 = splitnewlines(t2)
     def contextend(l, len):
         ret = l + opts.context
         if ret > len: