# HG changeset patch # User Joerg Sonnenberger # Date 1516984310 -3600 # Node ID 6a33e81e4c5e2dda5f17b47c4574fcbcbbecb7bf # Parent a9d07bd8f7583e068311008ae89d57858c94d87f mdiff: remove rewindhunk by yielding a bool first to indicate data Differential Revision: https://phab.mercurial-scm.org/D1942 diff -r a9d07bd8f758 -r 6a33e81e4c5e mercurial/mdiff.py --- 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'''