[Pkg-bazaar-commits] ./bzr/unstable r261: - auto-rollover of .bzr.log
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 07:51:34 UTC 2009
------------------------------------------------------------
revno: 261
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-04-15 12:50:12 +1000
message:
- auto-rollover of .bzr.log
modified:
NEWS
bzrlib/trace.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2005-04-15 02:29:03 +0000
+++ b/NEWS 2005-04-15 02:50:12 +0000
@@ -10,6 +10,8 @@
* New 'bzr log --verbose' shows a list of files changed in the
changeset. Patch from Sebastian Cote.
+ * Roll over ~/.bzr.log if it gets too large.
+
CHANGES:
@@ -44,7 +46,8 @@
PORTABILITY:
- * Fix opening of ~/.bzr.log on Windows. Patch from Andrew Bennetts.
+ * Fix opening of ~/.bzr.log on Windows. Patch from Andrew
+ Bennetts.
bzr-0.0.3 2005-04-06
=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py 2005-04-15 02:41:52 +0000
+++ b/bzrlib/trace.py 2005-04-15 02:50:12 +0000
@@ -77,6 +77,29 @@
+def _rollover_trace_maybe(trace_fname):
+ try:
+ size = os.stat(trace_fname)[stat.ST_SIZE]
+ if size <= 100000:
+ return
+ old_fname = trace_fname + '.old'
+
+ try:
+ # must remove before rename on windows
+ os.remove(old_fname)
+ except OSError:
+ pass
+
+ try:
+ # might fail if in use on windows
+ os.rename(trace_fname, old_fname)
+ except OSError:
+ pass
+ except OSError:
+ return
+
+
+
def create_tracefile(argv):
# TODO: Also show contents of /etc/lsb-release, if it can be parsed.
# Perhaps that should eventually go into the platform library?
@@ -89,11 +112,8 @@
_starttime = os.times()[4]
- # TODO: If the file exists and is too large, rename it to .old;
- # must handle failures of this because we can't rename an open
- # file on Windows.
-
trace_fname = os.path.join(os.path.expanduser('~/.bzr.log'))
+ _rollover_trace_maybe(trace_fname)
# buffering=1 means line buffered
_tracefile = codecs.open(trace_fname, 'at', 'utf8', buffering=1)
More information about the Pkg-bazaar-commits
mailing list