Patchwork D1942: mdiff: remove rewindhunk by yielding a bool first to indicate data

login
register
mail settings
Submitter phabricator
Date Jan. 26, 2018, 4:33 p.m.
Message ID <differential-rev-PHID-DREV-5ktmw2jix5xt4fz7pfpz-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27070/
State Superseded
Headers show

Comments

phabricator - Jan. 26, 2018, 4:33 p.m.
joerg.sonnenberger created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1942

AFFECTED FILES
  mercurial/mdiff.py

CHANGE DETAILS




To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -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'''