Rev 1: Trivial plugin to 'unpack' a repository in http://bzr.arbash-meinel.com/plugins/unpack_repo

John Arbash Meinel john at arbash-meinel.com
Tue Jul 15 18:41:01 BST 2008


At http://bzr.arbash-meinel.com/plugins/unpack_repo

------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20080715174101-wt0yhlic4hxxz7iy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: unpack_repo
timestamp: Tue 2008-07-15 12:41:01 -0500
message:
  Trivial plugin to 'unpack' a repository
added:
  __init__.py                    __init__.py-20080715174053-oi74zmwhj4xjxu79-1
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2008-07-15 17:41:01 +0000
@@ -0,0 +1,85 @@
+# Copyright (C) 2006 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
+
+"""Experiment with Bloom filters.
+
+Doesn't do much for bzrlib right now, but does provide a way to experiment with
+bloom filters.
+"""
+
+from bzrlib import (
+    commands,
+    )
+
+
+class cmd_create_unpacked_repo(commands.Command):
+    """Create a repository which is 'optimally' unpacked."""
+
+    takes_args = ['source_repo', 'target_repo']
+
+    def run(self, source_repo, target_repo):
+        from bzrlib import repository, trace, tsort, ui
+
+        source = repository.Repository.open(source_repo)
+        target = repository.Repository.open(target_repo)
+        source.lock_read()
+        target.lock_write()
+        try:
+            trace.note('finding revisions to fetch')
+            revision_ids = source.all_revision_ids()
+            parent_map = source.get_parent_map(revision_ids)
+            # Remove ghosts, or tsort dies
+            # for rev_id, parent_ids in parent_map:
+            #     new_parent_ids = tuple([p_id for p_id in parent_ids
+            #                                   if p_id in parent_map])
+            #     parent_map[rev_id] = new_parent_ids
+            trace.note('sorting revisions')
+            order = tsort.topo_sort(parent_map)
+            num_revs = len(revision_ids)
+            counts = self.pack_distribution(num_revs)
+            pb = ui.ui_factory.nested_progress_bar()
+            try:
+                cur = 0
+                for count in counts:
+                    cur += count
+                    pb.update('Fetching', cur, num_revs)
+                    target.fetch(source, order[cur-1])
+            finally:
+                pb.finished()
+        finally:
+            target.unlock()
+            source.unlock()
+
+    @staticmethod
+    def pack_distribution(total_revisions):
+        """Generate a list of the number of revisions to put in each pack.
+
+        :param total_revisions: The total number of revisions in the
+            repository.
+        """
+        if total_revisions == 0:
+            return [0]
+        digits = reversed(str(total_revisions))
+        result = []
+        for exponent, count in enumerate(digits):
+            size = 10 ** exponent
+            result.extend([size]*int(count))
+        result.reverse()
+        return result
+
+
+
+commands.register_command(cmd_create_unpacked_repo)



More information about the bazaar-commits mailing list