Mercurial > hg
comparison hgext/blackbox.py @ 28245:caa2a0c6fbb7
blackbox: log working directory version
Without this, while you could see the list of commands run,
it wasn't possible to identify what they were doing, because commads
could rely on revsets (including remote input which varies over time).
author | timeless <timeless@mozdev.org> |
---|---|
date | Tue, 09 Feb 2016 19:16:06 +0000 |
parents | c17d7b1c40be |
children | b862e793ec10 |
comparison
equal
deleted
inserted
replaced
28244:c17d7b1c40be | 28245:caa2a0c6fbb7 |
---|---|
33 | 33 |
34 import errno | 34 import errno |
35 import re | 35 import re |
36 | 36 |
37 from mercurial.i18n import _ | 37 from mercurial.i18n import _ |
38 from mercurial.node import hex | |
39 | |
38 from mercurial import ( | 40 from mercurial import ( |
39 cmdutil, | 41 cmdutil, |
40 util, | 42 util, |
41 ) | 43 ) |
42 | 44 |
61 def _closelog(vfs): | 63 def _closelog(vfs): |
62 path = vfs.join('blackbox.log') | 64 path = vfs.join('blackbox.log') |
63 fp = filehandles[path] | 65 fp = filehandles[path] |
64 del filehandles[path] | 66 del filehandles[path] |
65 fp.close() | 67 fp.close() |
68 | |
69 def hexfn(node): | |
70 if node is None: | |
71 return None | |
72 else: | |
73 return hex(node) | |
66 | 74 |
67 def wrapui(ui): | 75 def wrapui(ui): |
68 class blackboxui(ui.__class__): | 76 class blackboxui(ui.__class__): |
69 @util.propertycache | 77 @util.propertycache |
70 def track(self): | 78 def track(self): |
129 if fp: | 137 if fp: |
130 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') | 138 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') |
131 user = util.getuser() | 139 user = util.getuser() |
132 pid = str(util.getpid()) | 140 pid = str(util.getpid()) |
133 formattedmsg = msg[0] % msg[1:] | 141 formattedmsg = msg[0] % msg[1:] |
134 try: | 142 rev = '(unknown)' |
135 fp.write('%s %s (%s)> %s' % | 143 if util.safehasattr(self, '_bbrepo'): |
136 (date, user, pid, formattedmsg)) | 144 ctx = self._bbrepo[None] |
145 if ctx.rev() is not None: | |
146 rev = hexfn(ctx.node()) | |
147 else: | |
148 parents = ctx.parents() | |
149 rev = ('+'.join([hexfn(p.node()) for p in parents])) | |
150 try: | |
151 fp.write('%s %s @%s (%s)> %s' % | |
152 (date, user, rev, pid, formattedmsg)) | |
137 fp.flush() | 153 fp.flush() |
138 except IOError as err: | 154 except IOError as err: |
139 self.debug('warning: cannot write to blackbox.log: %s\n' % | 155 self.debug('warning: cannot write to blackbox.log: %s\n' % |
140 err.strerror) | 156 err.strerror) |
141 lastfp = fp | 157 if not lastfp or util.safehasattr(self, '_bbrepo'): |
158 lastfp = fp | |
142 | 159 |
143 def setrepo(self, repo): | 160 def setrepo(self, repo): |
144 self._bbvfs = repo.vfs | 161 self._bbvfs = repo.vfs |
162 self._bbrepo = repo | |
145 | 163 |
146 ui.__class__ = blackboxui | 164 ui.__class__ = blackboxui |
147 | 165 |
148 def uisetup(ui): | 166 def uisetup(ui): |
149 wrapui(ui) | 167 wrapui(ui) |