Mercurial > hg
comparison hgext/blackbox.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 9f70512ae2cf |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
61 | 61 |
62 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | 62 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
63 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 63 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
64 # be specifying the version(s) of Mercurial they are tested with, or | 64 # be specifying the version(s) of Mercurial they are tested with, or |
65 # leave the attribute unspecified. | 65 # leave the attribute unspecified. |
66 testedwith = 'ships-with-hg-core' | 66 testedwith = b'ships-with-hg-core' |
67 | 67 |
68 cmdtable = {} | 68 cmdtable = {} |
69 command = registrar.command(cmdtable) | 69 command = registrar.command(cmdtable) |
70 | 70 |
71 configtable = {} | 71 configtable = {} |
72 configitem = registrar.configitem(configtable) | 72 configitem = registrar.configitem(configtable) |
73 | 73 |
74 configitem( | 74 configitem( |
75 'blackbox', 'dirty', default=False, | 75 b'blackbox', b'dirty', default=False, |
76 ) | 76 ) |
77 configitem( | 77 configitem( |
78 'blackbox', 'maxsize', default='1 MB', | 78 b'blackbox', b'maxsize', default=b'1 MB', |
79 ) | 79 ) |
80 configitem( | 80 configitem( |
81 'blackbox', 'logsource', default=False, | 81 b'blackbox', b'logsource', default=False, |
82 ) | 82 ) |
83 configitem( | 83 configitem( |
84 'blackbox', 'maxfiles', default=7, | 84 b'blackbox', b'maxfiles', default=7, |
85 ) | 85 ) |
86 configitem( | 86 configitem( |
87 'blackbox', 'track', default=lambda: ['*'], | 87 b'blackbox', b'track', default=lambda: [b'*'], |
88 ) | 88 ) |
89 configitem( | 89 configitem( |
90 'blackbox', | 90 b'blackbox', |
91 'ignore', | 91 b'ignore', |
92 default=lambda: ['chgserver', 'cmdserver', 'extension'], | 92 default=lambda: [b'chgserver', b'cmdserver', b'extension'], |
93 ) | 93 ) |
94 configitem( | 94 configitem( |
95 'blackbox', 'date-format', default='%Y/%m/%d %H:%M:%S', | 95 b'blackbox', b'date-format', default=b'%Y/%m/%d %H:%M:%S', |
96 ) | 96 ) |
97 | 97 |
98 _lastlogger = loggingutil.proxylogger() | 98 _lastlogger = loggingutil.proxylogger() |
99 | 99 |
100 | 100 |
101 class blackboxlogger(object): | 101 class blackboxlogger(object): |
102 def __init__(self, ui, repo): | 102 def __init__(self, ui, repo): |
103 self._repo = repo | 103 self._repo = repo |
104 self._trackedevents = set(ui.configlist('blackbox', 'track')) | 104 self._trackedevents = set(ui.configlist(b'blackbox', b'track')) |
105 self._ignoredevents = set(ui.configlist('blackbox', 'ignore')) | 105 self._ignoredevents = set(ui.configlist(b'blackbox', b'ignore')) |
106 self._maxfiles = ui.configint('blackbox', 'maxfiles') | 106 self._maxfiles = ui.configint(b'blackbox', b'maxfiles') |
107 self._maxsize = ui.configbytes('blackbox', 'maxsize') | 107 self._maxsize = ui.configbytes(b'blackbox', b'maxsize') |
108 self._inlog = False | 108 self._inlog = False |
109 | 109 |
110 def tracked(self, event): | 110 def tracked(self, event): |
111 return ( | 111 return ( |
112 b'*' in self._trackedevents and event not in self._ignoredevents | 112 b'*' in self._trackedevents and event not in self._ignoredevents |
123 self._log(ui, event, msg, opts) | 123 self._log(ui, event, msg, opts) |
124 finally: | 124 finally: |
125 self._inlog = False | 125 self._inlog = False |
126 | 126 |
127 def _log(self, ui, event, msg, opts): | 127 def _log(self, ui, event, msg, opts): |
128 default = ui.configdate('devel', 'default-date') | 128 default = ui.configdate(b'devel', b'default-date') |
129 date = dateutil.datestr(default, ui.config('blackbox', 'date-format')) | 129 date = dateutil.datestr(default, ui.config(b'blackbox', b'date-format')) |
130 user = procutil.getuser() | 130 user = procutil.getuser() |
131 pid = '%d' % procutil.getpid() | 131 pid = b'%d' % procutil.getpid() |
132 changed = '' | 132 changed = b'' |
133 ctx = self._repo[None] | 133 ctx = self._repo[None] |
134 parents = ctx.parents() | 134 parents = ctx.parents() |
135 rev = '+'.join([hex(p.node()) for p in parents]) | 135 rev = b'+'.join([hex(p.node()) for p in parents]) |
136 if ui.configbool('blackbox', 'dirty') and ctx.dirty( | 136 if ui.configbool(b'blackbox', b'dirty') and ctx.dirty( |
137 missing=True, merge=False, branch=False | 137 missing=True, merge=False, branch=False |
138 ): | 138 ): |
139 changed = '+' | 139 changed = b'+' |
140 if ui.configbool('blackbox', 'logsource'): | 140 if ui.configbool(b'blackbox', b'logsource'): |
141 src = ' [%s]' % event | 141 src = b' [%s]' % event |
142 else: | 142 else: |
143 src = '' | 143 src = b'' |
144 try: | 144 try: |
145 fmt = '%s %s @%s%s (%s)%s> %s' | 145 fmt = b'%s %s @%s%s (%s)%s> %s' |
146 args = (date, user, rev, changed, pid, src, msg) | 146 args = (date, user, rev, changed, pid, src, msg) |
147 with loggingutil.openlogfile( | 147 with loggingutil.openlogfile( |
148 ui, | 148 ui, |
149 self._repo.vfs, | 149 self._repo.vfs, |
150 name='blackbox.log', | 150 name=b'blackbox.log', |
151 maxfiles=self._maxfiles, | 151 maxfiles=self._maxfiles, |
152 maxsize=self._maxsize, | 152 maxsize=self._maxsize, |
153 ) as fp: | 153 ) as fp: |
154 fp.write(fmt % args) | 154 fp.write(fmt % args) |
155 except (IOError, OSError) as err: | 155 except (IOError, OSError) as err: |
156 # deactivate this to avoid failed logging again | 156 # deactivate this to avoid failed logging again |
157 self._trackedevents.clear() | 157 self._trackedevents.clear() |
158 ui.debug( | 158 ui.debug( |
159 'warning: cannot write to blackbox.log: %s\n' | 159 b'warning: cannot write to blackbox.log: %s\n' |
160 % encoding.strtolocal(err.strerror) | 160 % encoding.strtolocal(err.strerror) |
161 ) | 161 ) |
162 return | 162 return |
163 _lastlogger.logger = self | 163 _lastlogger.logger = self |
164 | 164 |
182 # Set _lastlogger even if ui.log is not called. This gives blackbox a | 182 # Set _lastlogger even if ui.log is not called. This gives blackbox a |
183 # fallback place to log | 183 # fallback place to log |
184 if _lastlogger.logger is None: | 184 if _lastlogger.logger is None: |
185 _lastlogger.logger = logger | 185 _lastlogger.logger = logger |
186 | 186 |
187 repo._wlockfreeprefix.add('blackbox.log') | 187 repo._wlockfreeprefix.add(b'blackbox.log') |
188 | 188 |
189 | 189 |
190 @command( | 190 @command( |
191 'blackbox', | 191 b'blackbox', |
192 [('l', 'limit', 10, _('the number of events to show')),], | 192 [(b'l', b'limit', 10, _(b'the number of events to show')),], |
193 _('hg blackbox [OPTION]...'), | 193 _(b'hg blackbox [OPTION]...'), |
194 helpcategory=command.CATEGORY_MAINTENANCE, | 194 helpcategory=command.CATEGORY_MAINTENANCE, |
195 helpbasic=True, | 195 helpbasic=True, |
196 ) | 196 ) |
197 def blackbox(ui, repo, *revs, **opts): | 197 def blackbox(ui, repo, *revs, **opts): |
198 '''view the recent repository events | 198 '''view the recent repository events |
199 ''' | 199 ''' |
200 | 200 |
201 if not repo.vfs.exists('blackbox.log'): | 201 if not repo.vfs.exists(b'blackbox.log'): |
202 return | 202 return |
203 | 203 |
204 limit = opts.get(r'limit') | 204 limit = opts.get(r'limit') |
205 fp = repo.vfs('blackbox.log', 'r') | 205 fp = repo.vfs(b'blackbox.log', b'r') |
206 lines = fp.read().split('\n') | 206 lines = fp.read().split(b'\n') |
207 | 207 |
208 count = 0 | 208 count = 0 |
209 output = [] | 209 output = [] |
210 for line in reversed(lines): | 210 for line in reversed(lines): |
211 if count >= limit: | 211 if count >= limit: |
214 # count the commands by matching lines like: 2013/01/23 19:13:36 root> | 214 # count the commands by matching lines like: 2013/01/23 19:13:36 root> |
215 if re.match(br'^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} .*> .*', line): | 215 if re.match(br'^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} .*> .*', line): |
216 count += 1 | 216 count += 1 |
217 output.append(line) | 217 output.append(line) |
218 | 218 |
219 ui.status('\n'.join(reversed(output))) | 219 ui.status(b'\n'.join(reversed(output))) |