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

joerg.sonnenberger (Joerg Sonnenberger) phabricator at mercurial-scm.org
Thu Feb 1 21:47:20 UTC 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6a33e81e4c5e: mdiff: remove rewindhunk by yielding a bool first to indicate data (authored by joerg.sonnenberger, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1942?vs=5009&id=5083

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

AFFECTED FILES
  mercurial/mdiff.py

CHANGE DETAILS

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'''



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


More information about the Mercurial-devel mailing list