changeset 35852:6a33e81e4c5e

mdiff: remove rewindhunk by yielding a bool first to indicate data Differential Revision: https://phab.mercurial-scm.org/D1942
author Joerg Sonnenberger <joerg@bec.de>
date Fri, 26 Jan 2018 17:31:50 +0100
parents a9d07bd8f758
children 2f7ab4fb7711
files mercurial/mdiff.py
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mdiff.py	Fri Jan 26 02:14:39 2018 +0100
+++ b/mercurial/mdiff.py	Fri Jan 26 17:31:50 2018 +0100
@@ -307,22 +307,14 @@
             hunklines.append(_missing_newline_marker)
         hunks = (hunkrange, hunklines),
     else:
-        diffhunks = _unidiff(a, b, opts=opts)
-        try:
-            hunkrange, hunklines = next(diffhunks)
-        except StopIteration:
+        hunks = _unidiff(a, b, opts=opts)
+        if not next(hunks):
             return sentinel
 
         headerlines = [
             "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)),
             "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)),
         ]
-        def rewindhunks():
-            yield hunkrange, hunklines
-            for hr, hl in diffhunks:
-                yield hr, hl
-
-        hunks = rewindhunks()
 
     return headerlines, hunks
 
@@ -414,6 +406,7 @@
     #
     hunk = None
     ignoredlines = 0
+    has_hunks = False
     for s, stype in allblocks(t1, t2, opts, l1, l2):
         a1, a2, b1, b2 = s
         if stype != '!':
@@ -440,6 +433,9 @@
                 astart = hunk[1]
                 bstart = hunk[3]
             else:
+                if not has_hunks:
+                    has_hunks = True
+                    yield True
                 for x in yieldhunk(hunk):
                     yield x
         if prev:
@@ -456,8 +452,13 @@
         delta[len(delta):] = ['+' + x for x in new]
 
     if hunk:
+        if not has_hunks:
+            has_hunks = True
+            yield True
         for x in yieldhunk(hunk):
             yield x
+    elif not has_hunks:
+        yield False
 
 def b85diff(to, tn):
     '''print base85-encoded binary diff'''