Mercurial > hg
comparison hgext/blackbox.py @ 34274:a37e18b5f055
blackbox: simplify ui states
It seems cleaner to just remove `_partialinit`, `copy`, `__init__`. This
patch makes it so by using `getattr` in `log` so those fields do not need to
be existed.
Differential Revision: https://phab.mercurial-scm.org/D652
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 18 Sep 2017 15:56:08 -0700 |
parents | 029b33adbd17 |
children | 86a5df995880 |
comparison
equal
deleted
inserted
replaced
34273:b0790bebfcf8 | 34274:a37e18b5f055 |
---|---|
73 | 73 |
74 lastui = None | 74 lastui = None |
75 | 75 |
76 def wrapui(ui): | 76 def wrapui(ui): |
77 class blackboxui(ui.__class__): | 77 class blackboxui(ui.__class__): |
78 def __init__(self, src=None): | |
79 super(blackboxui, self).__init__(src) | |
80 if src is None: | |
81 self._partialinit() | |
82 else: | |
83 self._bbinlog = False | |
84 self._bbrepo = getattr(src, '_bbrepo', None) | |
85 | |
86 def _partialinit(self): | |
87 if self._bbvfs: | |
88 return | |
89 self._bbinlog = False | |
90 self._bbrepo = None | |
91 | |
92 def copy(self): | |
93 self._partialinit() | |
94 return self.__class__(self) | |
95 | |
96 @property | 78 @property |
97 def _bbvfs(self): | 79 def _bbvfs(self): |
98 repo = getattr(self, '_bbrepo', None) | 80 repo = getattr(self, '_bbrepo', None) |
99 if repo: | 81 if repo: |
100 return repo.vfs | 82 return repo.vfs |
138 return self._bbvfs(name, 'a') | 120 return self._bbvfs(name, 'a') |
139 | 121 |
140 def log(self, event, *msg, **opts): | 122 def log(self, event, *msg, **opts): |
141 global lastui | 123 global lastui |
142 super(blackboxui, self).log(event, *msg, **opts) | 124 super(blackboxui, self).log(event, *msg, **opts) |
143 self._partialinit() | |
144 | 125 |
145 if not '*' in self.track and not event in self.track: | 126 if not '*' in self.track and not event in self.track: |
146 return | 127 return |
147 | 128 |
148 if self._bbvfs: | 129 if self._bbvfs: |
153 # was seen. | 134 # was seen. |
154 ui = lastui | 135 ui = lastui |
155 | 136 |
156 if not ui: | 137 if not ui: |
157 return | 138 return |
158 if not lastui or ui._bbrepo: | 139 repo = getattr(ui, '_bbrepo', None) |
140 if not lastui or repo: | |
159 lastui = ui | 141 lastui = ui |
160 if ui._bbinlog: | 142 if getattr(ui, '_bbinlog', False): |
161 # recursion and failure guard | 143 # recursion and failure guard |
162 return | 144 return |
163 try: | 145 try: |
164 ui._bbinlog = True | 146 ui._bbinlog = True |
165 default = self.configdate('devel', 'default-date') | 147 default = self.configdate('devel', 'default-date') |
167 user = util.getuser() | 149 user = util.getuser() |
168 pid = '%d' % util.getpid() | 150 pid = '%d' % util.getpid() |
169 formattedmsg = msg[0] % msg[1:] | 151 formattedmsg = msg[0] % msg[1:] |
170 rev = '(unknown)' | 152 rev = '(unknown)' |
171 changed = '' | 153 changed = '' |
172 if ui._bbrepo: | 154 if repo: |
173 ctx = ui._bbrepo[None] | 155 ctx = repo[None] |
174 parents = ctx.parents() | 156 parents = ctx.parents() |
175 rev = ('+'.join([hex(p.node()) for p in parents])) | 157 rev = ('+'.join([hex(p.node()) for p in parents])) |
176 if (ui.configbool('blackbox', 'dirty') and | 158 if (ui.configbool('blackbox', 'dirty') and |
177 ctx.dirty(missing=True, merge=False, branch=False)): | 159 ctx.dirty(missing=True, merge=False, branch=False)): |
178 changed = '+' | 160 changed = '+' |
194 ui._bbinlog = False | 176 ui._bbinlog = False |
195 finally: | 177 finally: |
196 pass | 178 pass |
197 | 179 |
198 def setrepo(self, repo): | 180 def setrepo(self, repo): |
199 self._bbinlog = False | |
200 self._bbrepo = repo | 181 self._bbrepo = repo |
201 | 182 |
202 ui.__class__ = blackboxui | 183 ui.__class__ = blackboxui |
203 uimod.ui = blackboxui | 184 uimod.ui = blackboxui |
204 | 185 |