# HG changeset patch # User Matt Mackall # Date 2012-11-03 19:37:50 # Node ID 3326fd05eb1f5b5d870f7d9b85a276a07b2231db # Parent 42f8ee0e04ac41e01cff3191dfad29cec7b92733 formatter: add condwrite method This makes handling conditional output tidier diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -31,6 +31,10 @@ class baseformatter(object): '''do default text output while assigning data to item''' for k, v in zip(fields.split(), fielddata): self._item[k] = v + def condwrite(self, cond, fields, deftext, *fielddata, **opts): + '''do conditional write (primarily for plain formatter)''' + for k, v in zip(fields.split(), fielddata): + self._item[k] = v def plain(self, text, **opts): '''show raw text for non-templated mode''' pass @@ -51,6 +55,10 @@ class plainformatter(baseformatter): pass def write(self, fields, deftext, *fielddata, **opts): self._ui.write(deftext % fielddata, **opts) + def condwrite(self, cond, fields, deftext, *fielddata, **opts): + '''do conditional write''' + if cond: + self._ui.write(deftext % fielddata, **opts) def plain(self, text, **opts): self._ui.write(text, **opts) def end(self):