# HG changeset patch # User Augie Fackler # Date 1470420014 14400 # 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 -r cbeb2cb578b1 -r 160c829dd5d0 mercurial/patch.py --- a/mercurial/patch.py Fri Aug 05 14:00:08 2016 -0400 +++ b/mercurial/patch.py Fri Aug 05 14:00:14 2016 -0400 @@ -410,11 +410,7 @@ 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 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 @@ 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 @@ 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('***************'))