Mercurial > hg
comparison mercurial/cmdutil.py @ 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 | 01b39149ebb3 |
children | 2da601ab3125 |
comparison
equal
deleted
inserted
replaced
24355:ca4b89683078 | 24356:a38f384f2a57 |
---|---|
18 import lock as lockmod | 18 import lock as lockmod |
19 import crecord as crecordmod | 19 import crecord as crecordmod |
20 | 20 |
21 def parsealiases(cmd): | 21 def parsealiases(cmd): |
22 return cmd.lstrip("^").split("|") | 22 return cmd.lstrip("^").split("|") |
23 | |
24 def setupwrapcolorwrite(ui): | |
25 # wrap ui.write so diff output can be labeled/colorized | |
26 def wrapwrite(orig, *args, **kw): | |
27 label = kw.pop('label', '') | |
28 for chunk, l in patch.difflabel(lambda: args): | |
29 orig(chunk, label=label + l) | |
30 | |
31 oldwrite = ui.write | |
32 def wrap(*args, **kwargs): | |
33 return wrapwrite(oldwrite, *args, **kwargs) | |
34 setattr(ui, 'write', wrap) | |
35 return oldwrite | |
23 | 36 |
24 def recordfilter(ui, originalhunks): | 37 def recordfilter(ui, originalhunks): |
25 usecurses = ui.configbool('experimental', 'crecord', False) | 38 usecurses = ui.configbool('experimental', 'crecord', False) |
26 if usecurses: | 39 if usecurses: |
27 testfile = ui.config('experimental', 'crecordtest', None) | 40 testfile = ui.config('experimental', 'crecordtest', None) |
187 if tobackup: | 200 if tobackup: |
188 os.rmdir(backupdir) | 201 os.rmdir(backupdir) |
189 except OSError: | 202 except OSError: |
190 pass | 203 pass |
191 | 204 |
192 # wrap ui.write so diff output can be labeled/colorized | 205 oldwrite = setupwrapcolorwrite(ui) |
193 def wrapwrite(orig, *args, **kw): | |
194 label = kw.pop('label', '') | |
195 for chunk, l in patch.difflabel(lambda: args): | |
196 orig(chunk, label=label + l) | |
197 | |
198 oldwrite = ui.write | |
199 def wrap(*args, **kwargs): | |
200 return wrapwrite(oldwrite, *args, **kwargs) | |
201 setattr(ui, 'write', wrap) | |
202 | |
203 try: | 206 try: |
204 return commit(ui, repo, recordfunc, pats, opts) | 207 return commit(ui, repo, recordfunc, pats, opts) |
205 finally: | 208 finally: |
206 ui.write = oldwrite | 209 ui.write = oldwrite |
207 | 210 |