Show More
@@ -73,21 +73,6 b" configitem('blackbox', 'logsource'," | |||||
73 |
|
73 | |||
74 | lastui = None |
|
74 | lastui = None | |
75 |
|
75 | |||
76 | filehandles = {} |
|
|||
77 |
|
||||
78 | def _openlog(vfs): |
|
|||
79 | path = vfs.join('blackbox.log') |
|
|||
80 | if path in filehandles: |
|
|||
81 | return filehandles[path] |
|
|||
82 | filehandles[path] = fp = vfs('blackbox.log', 'a') |
|
|||
83 | return fp |
|
|||
84 |
|
||||
85 | def _closelog(vfs): |
|
|||
86 | path = vfs.join('blackbox.log') |
|
|||
87 | fp = filehandles[path] |
|
|||
88 | del filehandles[path] |
|
|||
89 | fp.close() |
|
|||
90 |
|
||||
91 | def wrapui(ui): |
|
76 | def wrapui(ui): | |
92 | class blackboxui(ui.__class__): |
|
77 | class blackboxui(ui.__class__): | |
93 | def __init__(self, src=None): |
|
78 | def __init__(self, src=None): | |
@@ -132,21 +117,23 b' def wrapui(ui):' | |||||
132 | self.debug("warning: cannot rename '%s' to '%s': %s\n" % |
|
117 | self.debug("warning: cannot rename '%s' to '%s': %s\n" % | |
133 | (newpath, oldpath, err.strerror)) |
|
118 | (newpath, oldpath, err.strerror)) | |
134 |
|
119 | |||
135 | fp = _openlog(self._bbvfs) |
|
|||
136 | maxsize = self.configbytes('blackbox', 'maxsize') |
|
120 | maxsize = self.configbytes('blackbox', 'maxsize') | |
|
121 | name = 'blackbox.log' | |||
137 | if maxsize > 0: |
|
122 | if maxsize > 0: | |
138 | st = self._bbvfs.fstat(fp) |
|
123 | try: | |
139 | if st.st_size >= maxsize: |
|
124 | st = self._bbvfs.stat(name) | |
140 | path = fp.name |
|
125 | except OSError: | |
141 |
|
|
126 | pass | |
142 | maxfiles = self.configint('blackbox', 'maxfiles', 7) |
|
127 | else: | |
143 |
f |
|
128 | if st.st_size >= maxsize: | |
144 | rotate(oldpath='%s.%d' % (path, i - 1), |
|
129 | path = self._bbvfs.join(name) | |
145 | newpath='%s.%d' % (path, i)) |
|
130 | maxfiles = self.configint('blackbox', 'maxfiles', 7) | |
146 | rotate(oldpath=path, |
|
131 | for i in xrange(maxfiles - 1, 1, -1): | |
147 |
|
|
132 | rotate(oldpath='%s.%d' % (path, i - 1), | |
148 | fp = _openlog(self._bbvfs) |
|
133 | newpath='%s.%d' % (path, i)) | |
149 | return fp |
|
134 | rotate(oldpath=path, | |
|
135 | newpath=maxfiles > 0 and path + '.1') | |||
|
136 | return self._bbvfs(name, 'a') | |||
150 |
|
137 | |||
151 | def _bbwrite(self, fmt, *args): |
|
138 | def _bbwrite(self, fmt, *args): | |
152 | self._bbfp.write(fmt % args) |
|
139 | self._bbfp.write(fmt % args) |
@@ -230,3 +230,57 b' Test log recursion from dirty status che' | |||||
230 |
|
230 | |||
231 | cleanup |
|
231 | cleanup | |
232 | $ cd .. |
|
232 | $ cd .. | |
|
233 | ||||
|
234 | #if chg | |||
|
235 | ||||
|
236 | when using chg, blackbox.log should get rotated correctly | |||
|
237 | ||||
|
238 | $ cat > $TESTTMP/noop.py << EOF | |||
|
239 | > from __future__ import absolute_import | |||
|
240 | > import time | |||
|
241 | > from mercurial import registrar, scmutil | |||
|
242 | > cmdtable = {} | |||
|
243 | > command = registrar.command(cmdtable) | |||
|
244 | > @command('noop') | |||
|
245 | > def noop(ui, repo): | |||
|
246 | > pass | |||
|
247 | > EOF | |||
|
248 | ||||
|
249 | $ hg init blackbox-chg | |||
|
250 | $ cd blackbox-chg | |||
|
251 | ||||
|
252 | $ cat > .hg/hgrc << EOF | |||
|
253 | > [blackbox] | |||
|
254 | > maxsize = 500B | |||
|
255 | > [extensions] | |||
|
256 | > # extension change forces chg to restart | |||
|
257 | > noop=$TESTTMP/noop.py | |||
|
258 | > EOF | |||
|
259 | ||||
|
260 | $ $PYTHON -c 'print("a" * 400)' > .hg/blackbox.log | |||
|
261 | $ chg noop | |||
|
262 | $ chg noop | |||
|
263 | $ chg noop | |||
|
264 | $ chg noop | |||
|
265 | $ chg noop | |||
|
266 | ||||
|
267 | $ cat > showsize.py << 'EOF' | |||
|
268 | > import os, sys | |||
|
269 | > limit = 500 | |||
|
270 | > for p in sys.argv[1:]: | |||
|
271 | > size = os.stat(p).st_size | |||
|
272 | > if size >= limit: | |||
|
273 | > desc = '>=' | |||
|
274 | > else: | |||
|
275 | > desc = '<' | |||
|
276 | > print('%s: %s %d' % (p, desc, limit)) | |||
|
277 | > EOF | |||
|
278 | ||||
|
279 | $ $PYTHON showsize.py .hg/blackbox* | |||
|
280 | .hg/blackbox.log: < 500 | |||
|
281 | .hg/blackbox.log.1: >= 500 | |||
|
282 | .hg/blackbox.log.2: >= 500 | |||
|
283 | ||||
|
284 | $ cd .. | |||
|
285 | ||||
|
286 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now