# HG changeset patch # User Augie Fackler # Date 2016-08-05 18:00:14 # Node ID 160c829dd5d0b156c4fbbb48d67a9c1a50292a4a # Parent cbeb2cb578b14f3ac893f75d544f1e0d1c814308 patch: use `iter(callable, sentinel)` instead of while True This is functionally equivalent, but is a little more concise. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -410,11 +410,7 @@ class linereader(object): return self.fp.readline() def __iter__(self): - while True: - l = self.readline() - if not l: - break - yield l + return iter(self.readline, '') class abstractbackend(object): def __init__(self, ui): @@ -1688,10 +1684,7 @@ def scanpatch(fp): def scanwhile(first, p): """scan lr while predicate holds""" lines = [first] - while True: - line = lr.readline() - if not line: - break + for line in iter(lr.readline, ''): if p(line): lines.append(line) else: @@ -1699,10 +1692,7 @@ def scanpatch(fp): break return lines - while True: - line = lr.readline() - if not line: - break + for line in iter(lr.readline, ''): if line.startswith('diff --git a/') or line.startswith('diff -r '): def notheader(line): s = line.split(None, 1) @@ -1772,10 +1762,7 @@ def iterhunks(fp): context = None lr = linereader(fp) - while True: - x = lr.readline() - if not x: - break + for x in iter(lr.readline, ''): if state == BFILE and ( (not context and x[0] == '@') or (context is not False and x.startswith('***************'))