Rev 1: A basic plugin that lets you rebuild your knit files. in http://bzr.arbash-meinel.com/plugins/rebuild_knit

John Arbash Meinel john at arbash-meinel.com
Wed Mar 14 16:05:58 GMT 2007


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

------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20070314160554-b914k3s4b2m3jlqo
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: rebuild_knit
timestamp: Wed 2007-03-14 11:05:54 -0500
message:
  A basic plugin that lets you rebuild your knit files.
  Currently it only supports rebuilding inventory.knit, but that is the one
  that needs it the most.
added:
  __init__.py                    __init__.py-20070314160550-5zi5l45h9nonub98-1
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2007-03-14 16:05:54 +0000
@@ -0,0 +1,86 @@
+# Copyright (C) 2007 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
+
+"""Rebuild knit files to improve compression.
+
+Older versions of bzr had a fixed window, with a new fulltext every 26
+revisions. Newer versions relax this, to allow only creating a fulltext once
+the size of the deltas is equal to the size of a fulltext (capped at 200
+deltas).
+
+This plugin allows you to rebuild a knit, so that it can take advantage of the
+increase in deltas.
+"""
+
+from bzrlib import (
+    branch,
+    commands,
+    knit,
+    option,
+    transport,
+    ui,
+    urlutils,
+    )
+
+
+def copy_knit_into(source_knit, target_knit):
+    """Copy all of the texts from source_knit into target_knit"""
+    # Just keep a specific count of parent texts around, to speed up insertion
+    # into the new knit.
+    parent_texts = {}
+    queue = []
+    version_ids = source_knit.versions()
+    pb = ui.ui_factory.nested_progress_bar()
+    try:
+        for count, version_id in enumerate(version_ids):
+            pb.update('Copying', count, len(version_ids))
+            parent_ids = source_knit.get_parents_with_ghosts(version_id)
+            lines = source_knit.get_lines(version_id)
+            cache_text = target_knit.add_lines_with_ghosts(version_id,
+                            parent_ids, lines, parent_texts=parent_texts)
+            parent_texts[version_id] = cache_text
+            queue.append(version_id)
+            if len(queue) > 10:
+                remove_version_id = queue.pop(0)
+                del parent_texts[remove_version_id]
+    finally:
+        pb.finished()
+
+
+class cmd_rebuild_inventory_knit(commands.Command):
+    """Rebuild the inventory.knit file to improve compression."""
+
+    takes_args = ['out_file']
+
+    def run(self, out_file=None, location='.'):
+        out_dir, out_fname = urlutils.split(out_file)
+        out_transport = transport.get_transport(out_dir)
+        out_knit = knit.KnitVersionedFile(out_fname, out_transport,
+                                          access_mode='w',
+                                          factory=knit.KnitPlainFactory(),
+                                          create=True,
+                                          )
+        local_branch = branch.Branch.open_containing(location)[0]
+        repo = local_branch.repository
+        repo.lock_read()
+        try:
+            source_inv_knit = repo.get_inventory_weave()
+            copy_knit_into(source_inv_knit, out_knit)
+        finally:
+            repo.unlock()
+
+
+commands.register_command(cmd_rebuild_inventory_knit)



More information about the bazaar-commits mailing list