Rev 4418: (mbp) remove deprecated progress bar and weave code in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jun 9 05:24:06 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4418
revision-id: pqm at pqm.ubuntu.com-20090609042402-bmecxutc27lsgu91
parent: pqm at pqm.ubuntu.com-20090609032718-j717ilvc5elzr91r
parent: mbp at sourcefrog.net-20090605230037-662frzolf4cph3a3
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-06-09 05:24:02 +0100
message:
  (mbp) remove deprecated progress bar and weave code
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
  bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
  bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
  bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
    ------------------------------------------------------------
    revno: 4415.1.6
    revision-id: mbp at sourcefrog.net-20090605230037-662frzolf4cph3a3
    parent: mbp at sourcefrog.net-20090605225707-76ye2itqn8qwbw1s
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 09:00:37 +1000
    message:
      Deprecate DotsProgressBar and TTYProgressBar
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
      bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
    ------------------------------------------------------------
    revno: 4415.1.5
    revision-id: mbp at sourcefrog.net-20090605225707-76ye2itqn8qwbw1s
    parent: mbp at sourcefrog.net-20090605225550-in32fxi6bmt3jv9a
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 08:57:07 +1000
    message:
      Delete unneeded InstrumentedProgress
    modified:
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
    ------------------------------------------------------------
    revno: 4415.1.4
    revision-id: mbp at sourcefrog.net-20090605225550-in32fxi6bmt3jv9a
    parent: mbp at sourcefrog.net-20090605224647-k03yoq55uw1qhwvi
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 08:55:50 +1000
    message:
      Deprecate child_progress and ChildProgress and remove old tests
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
    ------------------------------------------------------------
    revno: 4415.1.3
    revision-id: mbp at sourcefrog.net-20090605224647-k03yoq55uw1qhwvi
    parent: mbp at sourcefrog.net-20090605222201-wy2ew221lalqb1x3
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 08:46:47 +1000
    message:
      Remove ProgressBarStack and its tests deprecated since 1.12
    modified:
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
      bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
    ------------------------------------------------------------
    revno: 4415.1.2
    revision-id: mbp at sourcefrog.net-20090605222201-wy2ew221lalqb1x3
    parent: mbp at sourcefrog.net-20090605221749-802cdyewgju314s7
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 08:22:01 +1000
    message:
      Remove code to run weave.py as a script
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
    ------------------------------------------------------------
    revno: 4415.1.1
    revision-id: mbp at sourcefrog.net-20090605221749-802cdyewgju314s7
    parent: pqm at pqm.ubuntu.com-20090605155813-4bxv90z2pchl0jwd
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: deprecation
    timestamp: Sat 2009-06-06 08:17:49 +1000
    message:
      Deprecate ProgressBar factory
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
=== modified file 'NEWS'
--- a/NEWS	2009-06-08 23:38:54 +0000
+++ b/NEWS	2009-06-09 04:24:02 +0000
@@ -106,13 +106,19 @@
 
 * Added osutils.parent_directories(). (Ian Clatworthy)
 
+* ``bzrlib.progress.ProgressBar``, ``ChildProgress``, ``DotsProgressBar``,
+  ``TTYProgressBar`` and ``child_progress`` are now deprecated; use
+  ``ui_factory.nested_progress_bar`` instead.  (Martin Pool)
+
 * TreeTransformBase no longer assumes that limbo is provided via disk.
   DiskTreeTransform now provides disk functionality.  (Aaron Bentley)
 
-
 Internals
 *********
 
+* Remove ``weave.py`` script for accessing internals of old weave-format
+  repositories.  (Martin Pool)
+
 Testing
 *******
 

=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/progress.py	2009-06-05 23:00:37 +0000
@@ -36,11 +36,13 @@
     )
 from bzrlib.trace import mutter
 from bzrlib.symbol_versioning import (
+    deprecated_function,
     deprecated_in,
     deprecated_method,
     )
 
 
+# XXX: deprecated; can be removed when the ProgressBar factory is removed
 def _supports_progress(f):
     """Detect if we can use pretty progress bars on the output stream f.
 
@@ -140,6 +142,7 @@
         self.ui_factory.clear_term()
 
 
+ at deprecated_function(deprecated_in((1, 16, 0)))
 def ProgressBar(to_file=None, **kwargs):
     """Abstract factory"""
     if to_file is None:
@@ -163,75 +166,6 @@
         return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
 
 
-class ProgressBarStack(object):
-    """A stack of progress bars.
-
-    This class is deprecated: instead, ask the ui factory for a new progress
-    task and finish it when it's done.
-    """
-
-    @deprecated_method(deprecated_in((1, 12, 0)))
-    def __init__(self,
-                 to_file=None,
-                 show_pct=False,
-                 show_spinner=True,
-                 show_eta=False,
-                 show_bar=True,
-                 show_count=True,
-                 to_messages_file=None,
-                 klass=None):
-        """Setup the stack with the parameters the progress bars should have."""
-        if to_file is None:
-            to_file = sys.stderr
-        if to_messages_file is None:
-            to_messages_file = sys.stdout
-        self._to_file = to_file
-        self._show_pct = show_pct
-        self._show_spinner = show_spinner
-        self._show_eta = show_eta
-        self._show_bar = show_bar
-        self._show_count = show_count
-        self._to_messages_file = to_messages_file
-        self._stack = []
-        self._klass = klass or ProgressBar
-
-    def top(self):
-        if len(self._stack) != 0:
-            return self._stack[-1]
-        else:
-            return None
-
-    def bottom(self):
-        if len(self._stack) != 0:
-            return self._stack[0]
-        else:
-            return None
-
-    def get_nested(self):
-        """Return a nested progress bar."""
-        if len(self._stack) == 0:
-            func = self._klass
-        else:
-            func = self.top().child_progress
-        new_bar = func(to_file=self._to_file,
-                       show_pct=self._show_pct,
-                       show_spinner=self._show_spinner,
-                       show_eta=self._show_eta,
-                       show_bar=self._show_bar,
-                       show_count=self._show_count,
-                       to_messages_file=self._to_messages_file,
-                       _stack=self)
-        self._stack.append(new_bar)
-        return new_bar
-
-    def return_pb(self, bar):
-        """Return bar after its been used."""
-        if bar is not self._stack[-1]:
-            warnings.warn("%r is not currently active" % (bar,))
-        else:
-            self._stack.pop()
-
-
 class _BaseProgressBar(object):
 
     def __init__(self,
@@ -278,6 +212,7 @@
         self.to_messages_file.write(fmt_string % args)
         self.to_messages_file.write('\n')
 
+    @deprecated_function(deprecated_in((1, 16, 0)))
     def child_progress(self, **kwargs):
         return ChildProgress(**kwargs)
 
@@ -309,6 +244,7 @@
 
 class DotsProgressBar(_BaseProgressBar):
 
+    @deprecated_function(deprecated_in((1, 16, 0)))
     def __init__(self, **kwargs):
         _BaseProgressBar.__init__(self, **kwargs)
         self.last_msg = None
@@ -335,8 +271,6 @@
         self.tick()
 
 
-
-
 class TTYProgressBar(_BaseProgressBar):
     """Progress bar display object.
 
@@ -359,7 +293,7 @@
     """
     SPIN_CHARS = r'/-\|'
 
-
+    @deprecated_function(deprecated_in((1, 16, 0)))
     def __init__(self, **kwargs):
         from bzrlib.osutils import terminal_width
         _BaseProgressBar.__init__(self, **kwargs)
@@ -519,11 +453,10 @@
         #self.to_file.flush()
 
 
-
-
 class ChildProgress(_BaseProgressBar):
     """A progress indicator that pushes its data to the parent"""
 
+    @deprecated_function(deprecated_in((1, 16, 0)))
     def __init__(self, _stack, **kwargs):
         _BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
         self.parent = _stack.top()
@@ -565,23 +498,6 @@
         self.parent.note(*args, **kwargs)
 
 
-class InstrumentedProgress(TTYProgressBar):
-    """TTYProgress variant that tracks outcomes"""
-
-    def __init__(self, *args, **kwargs):
-        self.always_throttled = True
-        self.never_throttle = False
-        TTYProgressBar.__init__(self, *args, **kwargs)
-
-    def throttle(self, old_message):
-        if self.never_throttle:
-            result =  False
-        else:
-            result = TTYProgressBar.throttle(self, old_message)
-        if result is False:
-            self.always_throttled = False
-
-
 def str_tdelta(delt):
     if delt is None:
         return "-:--:--"

=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_progress.py	2009-06-05 23:00:37 +0000
@@ -18,29 +18,12 @@
 from StringIO import StringIO
 
 from bzrlib import errors
-from bzrlib.progress import (
-        DummyProgress,
-        ChildProgress,
-        TTYProgressBar,
-        DotsProgressBar,
-        ProgressBarStack,
-        InstrumentedProgress,
-        )
 from bzrlib.tests import TestCase
 from bzrlib.symbol_versioning import (
     deprecated_in,
     )
 
 
-class FakeStack:
-
-    def __init__(self, top):
-        self.__top = top
-
-    def top(self):
-        return self.__top
-
-
 class _TTYStringIO(StringIO):
     """A helper class which makes a StringIO look like a terminal"""
 
@@ -53,259 +36,3 @@
 
     def isatty(self):
         return False
-
-
-class TestProgress(TestCase):
-
-    def setUp(self):
-        TestCase.setUp(self)
-        q = DummyProgress()
-        self.top = ChildProgress(_stack=FakeStack(q))
-
-    def test_propogation(self):
-        self.top.update('foobles', 1, 2)
-        self.assertEqual(self.top.message, 'foobles')
-        self.assertEqual(self.top.current, 1)
-        self.assertEqual(self.top.total, 2)
-        self.assertEqual(self.top.child_fraction, 0)
-        child = ChildProgress(_stack=FakeStack(self.top))
-        child.update('baubles', 2, 4)
-        self.assertEqual(self.top.message, 'foobles')
-        self.assertEqual(self.top.current, 1)
-        self.assertEqual(self.top.total, 2)
-        self.assertEqual(self.top.child_fraction, 0.5)
-        grandchild = ChildProgress(_stack=FakeStack(child))
-        grandchild.update('barbells', 1, 2)
-        self.assertEqual(self.top.child_fraction, 0.625)
-        self.assertEqual(child.child_fraction, 0.5)
-        child.update('baubles', 3, 4)
-        self.assertEqual(child.child_fraction, 0)
-        self.assertEqual(self.top.child_fraction, 0.75)
-        grandchild.update('barbells', 1, 2)
-        self.assertEqual(self.top.child_fraction, 0.875)
-        grandchild.update('barbells', 2, 2)
-        self.assertEqual(self.top.child_fraction, 1)
-        child.update('baubles', 4, 4)
-        self.assertEqual(self.top.child_fraction, 1)
-        #test clamping
-        grandchild.update('barbells', 2, 2)
-        self.assertEqual(self.top.child_fraction, 1)
-
-    def test_implementations(self):
-        for implementation in (TTYProgressBar, DotsProgressBar,
-                               DummyProgress):
-            self.check_parent_handling(implementation)
-
-    def check_parent_handling(self, parentclass):
-        top = parentclass(to_file=StringIO())
-        top.update('foobles', 1, 2)
-        child = ChildProgress(_stack=FakeStack(top))
-        child.update('baubles', 4, 4)
-        top.update('lala', 2, 2)
-        child.update('baubles', 4, 4)
-
-    def test_stacking(self):
-        self.check_stack(TTYProgressBar, ChildProgress)
-        self.check_stack(DotsProgressBar, ChildProgress)
-        self.check_stack(DummyProgress, DummyProgress)
-
-    def check_stack(self, parent_class, child_class):
-        stack = self.applyDeprecated(
-            deprecated_in((1, 12, 0)),
-            ProgressBarStack,
-            klass=parent_class, to_file=StringIO())
-        parent = stack.get_nested()
-        try:
-            self.assertIs(parent.__class__, parent_class)
-            child = stack.get_nested()
-            try:
-                self.assertIs(child.__class__, child_class)
-            finally:
-                child.finished()
-        finally:
-            parent.finished()
-
-    def test_throttling(self):
-        pb = InstrumentedProgress(to_file=StringIO())
-        # instantaneous updates should be squelched
-        pb.update('me', 1, 1)
-        self.assertTrue(pb.always_throttled)
-        pb = InstrumentedProgress(to_file=StringIO())
-        # It's like an instant sleep(1)!
-        pb.start_time -= 1
-        # Updates after a second should not be squelched
-        pb.update('me', 1, 1)
-        self.assertFalse(pb.always_throttled)
-
-    def test_clear(self):
-        sio = StringIO()
-        pb = TTYProgressBar(to_file=sio, show_eta=False)
-        pb.width = 20 # Just make it easier to test
-        # This should not output anything
-        pb.clear()
-        # These two should not be displayed because
-        # of throttling
-        pb.update('foo', 1, 3)
-        pb.update('bar', 2, 3)
-        # So pb.clear() has nothing to do
-        pb.clear()
-
-        # Make sure the next update isn't throttled
-        pb.start_time -= 1
-        pb.update('baz', 3, 3)
-        pb.clear()
-
-        self.assertEqual('\r[=========] baz 3/3'
-                         '\r                   \r',
-                         sio.getvalue())
-
-    def test_no_eta(self):
-        # An old version of the progress bar would
-        # store every update if show_eta was false
-        # because the eta routine was where it was
-        # cleaned out
-        pb = InstrumentedProgress(to_file=StringIO(), show_eta=False)
-        # Just make sure this first few are throttled
-        pb.start_time += 5
-
-        # These messages are throttled, and don't contribute
-        for count in xrange(100):
-            pb.update('x', count, 300)
-        self.assertEqual(0, len(pb.last_updates))
-
-        # Unthrottle by time
-        pb.start_time -= 10
-
-        # These happen too fast, so only one gets through
-        for count in xrange(100):
-            pb.update('x', count+100, 200)
-        self.assertEqual(1, len(pb.last_updates))
-
-        pb.MIN_PAUSE = 0.0
-
-        # But all of these go through, don't let the
-        # last_update list grow without bound
-        for count in xrange(100):
-            pb.update('x', count+100, 200)
-
-        self.assertEqual(pb._max_last_updates, len(pb.last_updates))
-
-
-class TestProgressTypes(TestCase):
-    """Test that the right ProgressBar gets instantiated at the right time."""
-
-    def get_nested(self, outf, term, env_progress=None):
-        """Setup so that ProgressBar thinks we are in the supplied terminal."""
-        orig_term = os.environ.get('TERM')
-        orig_progress = os.environ.get('BZR_PROGRESS_BAR')
-        os.environ['TERM'] = term
-        if env_progress is not None:
-            os.environ['BZR_PROGRESS_BAR'] = env_progress
-        elif orig_progress is not None:
-            del os.environ['BZR_PROGRESS_BAR']
-
-        def reset():
-            if orig_term is None:
-                del os.environ['TERM']
-            else:
-                os.environ['TERM'] = orig_term
-            # We may have never created BZR_PROGRESS_BAR
-            # So we can't just delete like we can 'TERM' (which is always set)
-            if orig_progress is None:
-                if 'BZR_PROGRESS_BAR' in os.environ:
-                    del os.environ['BZR_PROGRESS_BAR']
-            else:
-                os.environ['BZR_PROGRESS_BAR'] = orig_progress
-
-        self.addCleanup(reset)
-
-        stack = self.applyDeprecated(
-            deprecated_in((1, 12, 0)),
-            ProgressBarStack,
-            to_file=outf)
-        pb = stack.get_nested()
-        pb.start_time -= 1 # Make sure it is ready to write
-        pb.width = 20 # And it is of reasonable size
-        return pb
-
-    def test_tty_progress(self):
-        # Make sure the ProgressBarStack thinks it is
-        # writing out to a terminal, and thus uses a TTYProgressBar
-        out = _TTYStringIO()
-        pb = self.get_nested(out, 'xterm')
-        self.assertIsInstance(pb, TTYProgressBar)
-        try:
-            pb.update('foo', 1, 2)
-            pb.update('bar', 2, 2)
-        finally:
-            pb.finished()
-
-        self.assertEqual('\r/ [====   ] foo 1/2'
-                         '\r- [=======] bar 2/2'
-                         '\r                   \r',
-                         out.getvalue())
-
-    def test_noninteractive_progress(self):
-        out = _NonTTYStringIO()
-        pb = self.get_nested(out, 'xterm')
-        self.assertIsInstance(pb, DummyProgress)
-        try:
-            pb.update('foo', 1, 2)
-            pb.update('bar', 2, 2)
-        finally:
-            pb.finished()
-        self.assertEqual('', out.getvalue())
-
-    def test_dots_progress(self):
-        # make sure we get the right progress bar when not on a terminal
-        out = _NonTTYStringIO()
-        pb = self.get_nested(out, 'xterm', 'dots')
-        self.assertIsInstance(pb, DotsProgressBar)
-        try:
-            pb.update('foo', 1, 2)
-            pb.update('bar', 2, 2)
-        finally:
-            pb.finished()
-        self.assertEqual('foo: .'
-                         '\nbar: .'
-                         '\n',
-                         out.getvalue())
-
-    def test_no_isatty_progress(self):
-        # Make sure ProgressBarStack handles a plain StringIO()
-        import cStringIO
-        out = cStringIO.StringIO()
-        pb = self.get_nested(out, 'xterm')
-        pb.finished()
-        self.assertIsInstance(pb, DummyProgress)
-
-    def test_dumb_progress(self):
-        # using a terminal that can't do cursor movement
-        out = _TTYStringIO()
-        pb = self.get_nested(out, 'dumb')
-        pb.finished()
-        self.assertIsInstance(pb, DummyProgress)
-
-    def test_progress_env_tty(self):
-        # The environ variable BZR_PROGRESS_BAR controls what type of
-        # progress bar we will get, even if it wouldn't usually be that type
-        import cStringIO
-
-        # Usually, this would be a DotsProgressBar
-        out = cStringIO.StringIO()
-        pb = self.get_nested(out, 'dumb', 'tty')
-        pb.finished()
-        # Even though we are not a tty, the env_var will override
-        self.assertIsInstance(pb, TTYProgressBar)
-
-    def test_progress_env_none(self):
-        # Even though we are in a valid tty, no progress
-        out = _TTYStringIO()
-        pb = self.get_nested(out, 'xterm', 'none')
-        pb.finished()
-        self.assertIsInstance(pb, DummyProgress)
-
-    def test_progress_env_invalid(self):
-        out = _TTYStringIO()
-        self.assertRaises(errors.InvalidProgressBarType, self.get_nested,
-            out, 'xterm', 'nonexistant')

=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2009-05-15 10:14:51 +0000
+++ b/bzrlib/tests/test_ui.py	2009-06-05 23:00:37 +0000
@@ -25,12 +25,6 @@
 
 import bzrlib
 import bzrlib.errors as errors
-from bzrlib.progress import (
-    DotsProgressBar,
-    ProgressBarStack,
-    ProgressTask,
-    TTYProgressBar,
-    )
 from bzrlib.symbol_versioning import (
     deprecated_in,
     )
@@ -164,33 +158,6 @@
         pb2.finished()
         pb1.finished()
 
-    def test_progress_stack(self):
-        # test the progress bar stack which the default text factory
-        # uses.
-        stderr = StringIO()
-        stdout = StringIO()
-        # make a stack, which accepts parameters like a pb.
-        stack = self.applyDeprecated(
-            deprecated_in((1, 12, 0)),
-            ProgressBarStack,
-            to_file=stderr, to_messages_file=stdout)
-        # but is not one
-        self.assertFalse(getattr(stack, 'note', False))
-        pb1 = stack.get_nested()
-        pb2 = stack.get_nested()
-        warnings, _ = self.callCatchWarnings(pb1.finished)
-        self.assertEqual(len(warnings), 1)
-        pb2.finished()
-        pb1.finished()
-        # the text ui factory never actually removes the stack once its setup.
-        # we need to be able to nest again correctly from here.
-        pb1 = stack.get_nested()
-        pb2 = stack.get_nested()
-        warnings, _ = self.callCatchWarnings(pb1.finished)
-        self.assertEqual(len(warnings), 1)
-        pb2.finished()
-        pb1.finished()
-
     def assert_get_bool_acceptance_of_user_input(self, factory):
         factory.stdin = StringIO("y\nyes with garbage\n"
                                  "yes\nn\nnot an answer\n"

=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py	2009-04-08 16:33:19 +0000
+++ b/bzrlib/weave.py	2009-06-05 22:22:01 +0000
@@ -1,6 +1,4 @@
-#! /usr/bin/python
-
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2009 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
@@ -1025,6 +1023,7 @@
         wr._add(name, lines, [wr._lookup(i) for i in combined_parents[name]])
     return wr
 
+
 def _reweave_parent_graphs(wa, wb):
     """Return combined parent ancestry for two weaves.
 
@@ -1035,206 +1034,3 @@
             p = combined.setdefault(name, set())
             p.update(map(weave._idx_to_name, weave._parents[idx]))
     return combined
-
-
-def weave_toc(w):
-    """Show the weave's table-of-contents"""
-    print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')
-    for i in (6, 50, 10, 10):
-        print '-' * i,
-    print
-    for i in range(w.num_versions()):
-        sha1 = w._sha1s[i]
-        name = w._names[i]
-        parent_str = ' '.join(map(str, w._parents[i]))
-        print '%6d %-50.50s %10.10s %s' % (i, name, sha1, parent_str)
-
-
-
-def weave_stats(weave_file, pb):
-    from bzrlib.weavefile import read_weave
-
-    wf = file(weave_file, 'rb')
-    w = read_weave(wf)
-    # FIXME: doesn't work on pipes
-    weave_size = wf.tell()
-
-    total = 0
-    vers = len(w)
-    for i in range(vers):
-        pb.update('checking sizes', i, vers)
-        for origin, lineno, line in w._extract([i]):
-            total += len(line)
-
-    pb.clear()
-
-    print 'versions          %9d' % vers
-    print 'weave file        %9d bytes' % weave_size
-    print 'total contents    %9d bytes' % total
-    print 'compression ratio %9.2fx' % (float(total) / float(weave_size))
-    if vers:
-        avg = total/vers
-        print 'average size      %9d bytes' % avg
-        print 'relative size     %9.2fx' % (float(weave_size) / float(avg))
-
-
-def usage():
-    print """bzr weave tool
-
-Experimental tool for weave algorithm.
-
-usage:
-    weave init WEAVEFILE
-        Create an empty weave file
-    weave get WEAVEFILE VERSION
-        Write out specified version.
-    weave check WEAVEFILE
-        Check consistency of all versions.
-    weave toc WEAVEFILE
-        Display table of contents.
-    weave add WEAVEFILE NAME [BASE...] < NEWTEXT
-        Add NEWTEXT, with specified parent versions.
-    weave annotate WEAVEFILE VERSION
-        Display origin of each line.
-    weave merge WEAVEFILE VERSION1 VERSION2 > OUT
-        Auto-merge two versions and display conflicts.
-    weave diff WEAVEFILE VERSION1 VERSION2
-        Show differences between two versions.
-
-example:
-
-    % weave init foo.weave
-    % vi foo.txt
-    % weave add foo.weave ver0 < foo.txt
-    added version 0
-
-    (create updated version)
-    % vi foo.txt
-    % weave get foo.weave 0 | diff -u - foo.txt
-    % weave add foo.weave ver1 0 < foo.txt
-    added version 1
-
-    % weave get foo.weave 0 > foo.txt       (create forked version)
-    % vi foo.txt
-    % weave add foo.weave ver2 0 < foo.txt
-    added version 2
-
-    % weave merge foo.weave 1 2 > foo.txt   (merge them)
-    % vi foo.txt                            (resolve conflicts)
-    % weave add foo.weave merged 1 2 < foo.txt     (commit merged version)
-
-"""
-
-
-
-def main(argv):
-    import sys
-    import os
-    try:
-        import bzrlib
-    except ImportError:
-        # in case we're run directly from the subdirectory
-        sys.path.append('..')
-        import bzrlib
-    from bzrlib.weavefile import write_weave, read_weave
-    from bzrlib.progress import ProgressBar
-
-    try:
-        import psyco
-        psyco.full()
-    except ImportError:
-        pass
-
-    if len(argv) < 2:
-        usage()
-        return 0
-
-    cmd = argv[1]
-
-    def readit():
-        return read_weave(file(argv[2], 'rb'))
-
-    if cmd == 'help':
-        usage()
-    elif cmd == 'add':
-        w = readit()
-        # at the moment, based on everything in the file
-        name = argv[3]
-        parents = map(int, argv[4:])
-        lines = sys.stdin.readlines()
-        ver = w.add(name, parents, lines)
-        write_weave(w, file(argv[2], 'wb'))
-        print 'added version %r %d' % (name, ver)
-    elif cmd == 'init':
-        fn = argv[2]
-        if os.path.exists(fn):
-            raise IOError("file exists")
-        w = Weave()
-        write_weave(w, file(fn, 'wb'))
-    elif cmd == 'get': # get one version
-        w = readit()
-        sys.stdout.writelines(w.get_iter(int(argv[3])))
-
-    elif cmd == 'diff':
-        w = readit()
-        fn = argv[2]
-        v1, v2 = map(int, argv[3:5])
-        lines1 = w.get(v1)
-        lines2 = w.get(v2)
-        diff_gen = bzrlib.patiencediff.unified_diff(lines1, lines2,
-                                '%s version %d' % (fn, v1),
-                                '%s version %d' % (fn, v2))
-        sys.stdout.writelines(diff_gen)
-
-    elif cmd == 'annotate':
-        w = readit()
-        # newline is added to all lines regardless; too hard to get
-        # reasonable formatting otherwise
-        lasto = None
-        for origin, text in w.annotate(int(argv[3])):
-            text = text.rstrip('\r\n')
-            if origin == lasto:
-                print '      | %s' % (text)
-            else:
-                print '%5d | %s' % (origin, text)
-                lasto = origin
-
-    elif cmd == 'toc':
-        weave_toc(readit())
-
-    elif cmd == 'stats':
-        weave_stats(argv[2], ProgressBar())
-
-    elif cmd == 'check':
-        w = readit()
-        pb = ProgressBar()
-        w.check(pb)
-        pb.clear()
-        print '%d versions ok' % w.num_versions()
-
-    elif cmd == 'inclusions':
-        w = readit()
-        print ' '.join(map(str, w.inclusions([int(argv[3])])))
-
-    elif cmd == 'parents':
-        w = readit()
-        print ' '.join(map(str, w._parents[int(argv[3])]))
-
-    elif cmd == 'plan-merge':
-        # replaced by 'bzr weave-plan-merge'
-        w = readit()
-        for state, line in w.plan_merge(int(argv[3]), int(argv[4])):
-            if line:
-                print '%14s | %s' % (state, line),
-    elif cmd == 'merge':
-        # replaced by 'bzr weave-merge-text'
-        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)
-
-
-if __name__ == '__main__':
-    import sys
-    sys.exit(main(sys.argv))




More information about the bazaar-commits mailing list