##// END OF EJS Templates
blackbox: properly replace ui class...
timeless -
r28248:851c41a2 default
parent child Browse files
Show More
@@ -44,6 +44,7 b' from mercurial.node import hex'
44
44
45 from mercurial import (
45 from mercurial import (
46 cmdutil,
46 cmdutil,
47 ui as uimod,
47 util,
48 util,
48 )
49 )
49
50
@@ -79,6 +80,26 b' def hexfn(node):'
79
80
80 def wrapui(ui):
81 def wrapui(ui):
81 class blackboxui(ui.__class__):
82 class blackboxui(ui.__class__):
83 def __init__(self, src=None):
84 super(blackboxui, self).__init__(src)
85 if src is None:
86 self._partialinit()
87 else:
88 self._bbfp = src._bbfp
89 self._bbrepo = src._bbrepo
90 self._bbvfs = src._bbvfs
91
92 def _partialinit(self):
93 if util.safehasattr(self, '_bbvfs'):
94 return
95 self._bbfp = None
96 self._bbrepo = None
97 self._bbvfs = None
98
99 def copy(self):
100 self._partialinit()
101 return self.__class__(self)
102
82 @util.propertycache
103 @util.propertycache
83 def track(self):
104 def track(self):
84 return self.configlist('blackbox', 'track', ['*'])
105 return self.configlist('blackbox', 'track', ['*'])
@@ -122,13 +143,14 b' def wrapui(ui):'
122 def log(self, event, *msg, **opts):
143 def log(self, event, *msg, **opts):
123 global lastui
144 global lastui
124 super(blackboxui, self).log(event, *msg, **opts)
145 super(blackboxui, self).log(event, *msg, **opts)
146 self._partialinit()
125
147
126 if not '*' in self.track and not event in self.track:
148 if not '*' in self.track and not event in self.track:
127 return
149 return
128
150
129 if util.safehasattr(self, '_bbfp'):
151 if self._bbfp:
130 ui = self
152 ui = self
131 elif util.safehasattr(self, '_bbvfs'):
153 elif self._bbvfs:
132 try:
154 try:
133 self._bbfp = self._openlogfile()
155 self._bbfp = self._openlogfile()
134 except (IOError, OSError) as err:
156 except (IOError, OSError) as err:
@@ -143,15 +165,14 b' def wrapui(ui):'
143 # was seen.
165 # was seen.
144 ui = lastui
166 ui = lastui
145
167
146 if (util.safehasattr(ui, '_bbfp') and
168 if ui and ui._bbfp:
147 ui._bbfp is not None):
148 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
169 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
149 user = util.getuser()
170 user = util.getuser()
150 pid = str(util.getpid())
171 pid = str(util.getpid())
151 formattedmsg = msg[0] % msg[1:]
172 formattedmsg = msg[0] % msg[1:]
152 rev = '(unknown)'
173 rev = '(unknown)'
153 changed = ''
174 changed = ''
154 if util.safehasattr(ui, '_bbrepo'):
175 if ui._bbrepo:
155 ctx = ui._bbrepo[None]
176 ctx = ui._bbrepo[None]
156 if ctx.rev() is not None:
177 if ctx.rev() is not None:
157 rev = hexfn(ctx.node())
178 rev = hexfn(ctx.node())
@@ -169,14 +190,16 b' def wrapui(ui):'
169 except IOError as err:
190 except IOError as err:
170 self.debug('warning: cannot write to blackbox.log: %s\n' %
191 self.debug('warning: cannot write to blackbox.log: %s\n' %
171 err.strerror)
192 err.strerror)
172 if not lastui or util.safehasattr(ui, '_bbrepo'):
193 if not lastui or ui._bbrepo:
173 lastui = ui
194 lastui = ui
174
195
175 def setrepo(self, repo):
196 def setrepo(self, repo):
197 self._bbfp = None
198 self._bbrepo = repo
176 self._bbvfs = repo.vfs
199 self._bbvfs = repo.vfs
177 self._bbrepo = repo
178
200
179 ui.__class__ = blackboxui
201 ui.__class__ = blackboxui
202 uimod.ui = blackboxui
180
203
181 def uisetup(ui):
204 def uisetup(ui):
182 wrapui(ui)
205 wrapui(ui)
@@ -178,8 +178,15 b' log rotation'
178
178
179 result: None
179 result: None
180 $ hg blackbox
180 $ hg blackbox
181 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox
181 1970/01/01 00:00:00 bob @0e46349438790c460c5c9f7546bfcd39b267bbd2 (5000)> commit -m commit2 -d 2000-01-02 foo
182 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox exited 0 after * seconds (glob)
182 1970/01/01 00:00:00 bob @0e46349438790c460c5c9f7546bfcd39b267bbd2 (5000)> updated served branch cache in * seconds (glob)
183 1970/01/01 00:00:00 bob @0e46349438790c460c5c9f7546bfcd39b267bbd2 (5000)> wrote served branch cache with 1 labels and 1 nodes
184 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> commit -m commit2 -d 2000-01-02 foo exited 0 after * seconds (glob)
185 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> log -r 0
186 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> writing .hg/cache/tags2-visible with 0 tags
187 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> log -r 0 exited 0 after * seconds (glob)
188 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> log -r tip
189 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> log -r tip exited 0 after * seconds (glob)
183 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> blackbox
190 1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> blackbox
184
191
185 cleanup
192 cleanup
General Comments 0
You need to be logged in to leave comments. Login now