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