Mercurial > hg-stable
changeset 24356:a38f384f2a57
record: consolidate ui.write wrapping in a function
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Mon, 16 Mar 2015 15:30:33 -0700 |
parents | ca4b89683078 |
children | 2da601ab3125 |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue Mar 17 18:20:24 2015 +0900 +++ b/mercurial/cmdutil.py Mon Mar 16 15:30:33 2015 -0700 @@ -21,6 +21,19 @@ def parsealiases(cmd): return cmd.lstrip("^").split("|") +def setupwrapcolorwrite(ui): + # wrap ui.write so diff output can be labeled/colorized + def wrapwrite(orig, *args, **kw): + label = kw.pop('label', '') + for chunk, l in patch.difflabel(lambda: args): + orig(chunk, label=label + l) + + oldwrite = ui.write + def wrap(*args, **kwargs): + return wrapwrite(oldwrite, *args, **kwargs) + setattr(ui, 'write', wrap) + return oldwrite + def recordfilter(ui, originalhunks): usecurses = ui.configbool('experimental', 'crecord', False) if usecurses: @@ -189,17 +202,7 @@ except OSError: pass - # wrap ui.write so diff output can be labeled/colorized - def wrapwrite(orig, *args, **kw): - label = kw.pop('label', '') - for chunk, l in patch.difflabel(lambda: args): - orig(chunk, label=label + l) - - oldwrite = ui.write - def wrap(*args, **kwargs): - return wrapwrite(oldwrite, *args, **kwargs) - setattr(ui, 'write', wrap) - + oldwrite = setupwrapcolorwrite(ui) try: return commit(ui, repo, recordfunc, pats, opts) finally: