[patch] add some weave-debugging commands

Martin Pool mbp at sourcefrog.net
Tue Mar 21 12:20:04 GMT 2006


At the moment bzrlib/weave.py can be invoked as a python script to poke
around in weaves for purposes of debugging (e.g. naughty proxy
problems.)  This starts to add two of them as hidden commands within the
regular commandline framework.

-- 
Martin
-------------- next part --------------
=== added file 'b/bzrlib/weave_commands.py'
--- /dev/null	
+++ b/bzrlib/weave_commands.py	
@@ -0,0 +1,57 @@
+# Copyright (C) 2006 by Canonical Ltd
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""builtin bzr commands relating to individual weave files
+
+These should never normally need to be used by end users, but might be
+of interest in debugging or data recovery.
+"""
+
+import sys
+
+from bzrlib.commands import Command
+
+class cmd_weave_list(Command):
+    """List the revision ids present in a weave, in alphabetical order"""
+
+    hidden = True
+    takes_args = ['weave_filename']
+
+    def run(self, weave_filename):
+        from bzrlib.weavefile import read_weave
+        weave = read_weave(file(weave_filename, 'rb'))
+        names = weave.versions()
+        names.sort()
+        print '\n'.join(names)
+
+
+class cmd_weave_join(Command):
+    """Join the contents of two weave files.
+
+    The resulting weave is sent to stdout.
+
+    This command is only intended for bzr developer use.
+    """
+
+    hidden = True
+    takes_args = ['weave1', 'weave2']
+
+    def run(self, weave1, weave2):
+        from bzrlib.weavefile import read_weave, write_weave
+        w1 = read_weave(file(weave1, 'rb'))
+        w2 = read_weave(file(weave2, 'rb'))
+        w1.join(w2)
+        write_weave(w1, sys.stdout)

=== modified file 'a/bzrlib/builtins.py'
--- a/bzrlib/builtins.py	
+++ b/bzrlib/builtins.py	
@@ -2413,6 +2413,8 @@
 # these get imported and then picked up by the scan for cmd_*
 # TODO: Some more consistent way to split command definitions across files;
 # we do need to load at least some information about them to know of 
-# aliases.
+# aliases.  ideally we would avoid loading the implementation until the
+# details were needed.
 from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
 from bzrlib.sign_my_commits import cmd_sign_my_commits
+from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join

=== modified file 'a/bzrlib/inventory.py'
--- a/bzrlib/inventory.py	
+++ b/bzrlib/inventory.py	
@@ -543,7 +543,7 @@
             w = tree.get_weave(self.file_id)
 
         mutter('check version {%s} of {%s}', tree_revision_id, self.file_id)
-        checker.checked_text_cnt += 1 
+        checker.checked_text_cnt += 1
         # We can't check the length, because Weave doesn't store that
         # information, and the whole point of looking at the weave's
         # sha1sum is that we don't have to extract the text.

=== modified file 'a/bzrlib/weave.py'
--- a/bzrlib/weave.py	
+++ b/bzrlib/weave.py	
@@ -1367,13 +1367,12 @@
         w = readit()
         p = w.plan_merge(int(argv[3]), int(argv[4]))
         sys.stdout.writelines(w.weave_merge(p))
-            
     else:
         raise ValueError('unknown command %r' % cmd)
     
 
 
-def profile_main(argv): 
+def profile_main(argv):
     import tempfile, hotshot, hotshot.stats
 
     prof_f = tempfile.NamedTemporaryFile()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060321/201d9167/attachment.pgp 


More information about the bazaar mailing list