Rev 1: Just a simple command to time dumping all revision trees from a repo. in http://bzr.arbash-meinel.com/plugins/dump
John Arbash Meinel
john at arbash-meinel.com
Wed Mar 4 03:45:42 GMT 2009
At http://bzr.arbash-meinel.com/plugins/dump
------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20090304034534-zjytp6m07p65frvy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dump
timestamp: Tue 2009-03-03 21:45:34 -0600
message:
Just a simple command to time dumping all revision trees from a repo.
Also, is able to check what strings are/aren't interned.
-------------- next part --------------
=== added file '.bzrignore'
--- a/.bzrignore 1970-01-01 00:00:00 +0000
+++ b/.bzrignore 2009-03-04 03:45:34 +0000
@@ -0,0 +1,2 @@
+./build
+./dump_pyx.c
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2009-03-04 03:45:34 +0000
@@ -0,0 +1,49 @@
+
+from bzrlib import commands
+
+class cmd_dump(commands.Command):
+ """Load all revision and inventory texts."""
+
+ takes_args = ['location']
+
+ def run(self, location):
+ from bzrlib import cache_utf8, repository, trace, ui
+ import dump_pyx
+ repo = repository.Repository.open(location)
+ repo.lock_read()
+ try:
+ revs = repo.revisions.keys()
+ rev_ids = [rev[0] for rev in revs]
+ n_interned = sum([1 for r in rev_ids if dump_pyx.is_interned(r)])
+ trace.note('interned: %d/%d', n_interned, len(rev_ids))
+ pb = ui.ui_factory.nested_progress_bar()
+ try:
+ fids = 0
+ fids_interned = 0
+ rids = 0
+ rids_interned = 0
+ for idx, rt in enumerate(repo.revision_trees(rev_ids)):
+ pb.update('extracting', idx, len(rev_ids))
+ for path, ie in rt.iter_entries_by_dir():
+ if dump_pyx.is_interned(ie.file_id):
+ fids_interned += 1
+ fids += 1
+ if dump_pyx.is_interned(ie.parent_id):
+ fids_interned += 1
+ fids += 1
+ if dump_pyx.is_interned(ie.revision):
+ rids_interned += 1
+ rids += 1
+ finally:
+ pb.finished()
+ text_keys = repo.texts.keys()
+ del revs, rev_ids, text_keys
+ finally:
+ repo.unlock()
+ trace.note('interned fids: %d/%d %.1f%%', fids_interned, fids,
+ 100.0 * fids_interned / fids)
+ trace.note('interned rids: %d/%d %.1f%%', rids_interned, rids,
+ 100.0 * rids_interned / rids)
+ trace.note('cache: %s', len(cache_utf8._unicode_to_utf8_map))
+
+commands.register_command(cmd_dump)
=== added file 'dump_pyx.pyx'
--- a/dump_pyx.pyx 1970-01-01 00:00:00 +0000
+++ b/dump_pyx.pyx 2009-03-04 03:45:34 +0000
@@ -0,0 +1,9 @@
+
+cdef extern from "Python.h":
+ int PyString_CheckExact(object)
+ int PyString_CHECK_INTERNED(object)
+
+def is_interned(s):
+ if PyString_CheckExact(s) and PyString_CHECK_INTERNED(s):
+ return True
+ return False
=== added file 'setup.py'
--- a/setup.py 1970-01-01 00:00:00 +0000
+++ b/setup.py 2009-03-04 03:45:34 +0000
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+import os
+from distutils.core import setup
+
+bzr_plugin_name = 'groupcompress'
+
+bzr_plugin_version = (1, 6, 0, 'dev', 0)
+
+from distutils import log
+from distutils.errors import CCompilerError, DistutilsPlatformError
+from distutils.extension import Extension
+ext_modules = []
+try:
+ from Pyrex.Distutils import build_ext
+except ImportError:
+ have_pyrex = False
+ # try to build the extension from the prior generated source.
+ print
+ print ("The python package 'Pyrex' is not available."
+ " If the .c files are available,")
+ print ("they will be built,"
+ " but modifying the .pyx files will not rebuild them.")
+ print
+ from distutils.command.build_ext import build_ext
+else:
+ have_pyrex = True
+
+
+class build_ext_if_possible(build_ext):
+
+ user_options = build_ext.user_options + [
+ ('allow-python-fallback', None,
+ "When an extension cannot be built, allow falling"
+ " back to the pure-python implementation.")
+ ]
+
+ def initialize_options(self):
+ build_ext.initialize_options(self)
+ self.allow_python_fallback = False
+
+ def run(self):
+ try:
+ build_ext.run(self)
+ except DistutilsPlatformError, e:
+ if not self.allow_python_fallback:
+ log.warn('\n Cannot build extensions.\n'
+ ' Use "build_ext --allow-python-fallback" to use'
+ ' slower python implementations instead.\n')
+ raise
+ log.warn(str(e))
+ log.warn('\n Extensions cannot be built.\n'
+ ' Using the slower Python implementations instead.\n')
+
+ def build_extension(self, ext):
+ try:
+ build_ext.build_extension(self, ext)
+ except CCompilerError:
+ if not self.allow_python_fallback:
+ log.warn('\n Cannot build extension (%s).\n'
+ ' Use "build_ext --allow-python-fallback" to use'
+ ' slower python implementations instead.\n'
+ % (ext.name,))
+ raise
+ log.warn('\n Building of "%s" extension failed.\n'
+ ' Using the slower Python implementation instead.'
+ % (ext.name,))
+
+
+# Override the build_ext if we have Pyrex available
+unavailable_files = []
+
+
+def add_pyrex_extension(module_name, extra_source=[]):
+ """Add a pyrex module to build.
+
+ This will use Pyrex to auto-generate the .c file if it is available.
+ Otherwise it will fall back on the .c file. If the .c file is not
+ available, it will warn, and not add anything.
+
+ You can pass any extra options to Extension through kwargs. One example is
+ 'libraries = []'.
+
+ :param module_name: The python path to the module. This will be used to
+ determine the .pyx and .c files to use.
+ """
+ path = module_name.replace('.', '/')
+ pyrex_name = path + '.pyx'
+ c_name = path + '.c'
+ # Manually honour package_dir :(
+ module_name = 'bzrlib.plugins.dump.' + module_name
+ if have_pyrex:
+ source = [pyrex_name]
+ elif not os.path.isfile(c_name):
+ unavailable_files.append(c_name)
+ return
+ else:
+ source = [c_name]
+ source.extend(extra_source)
+ ext_modules.append(Extension(module_name, source,
+ extra_compile_args = ['-O3']))
+
+add_pyrex_extension('dump_pyx')
+
+
+if __name__ == '__main__':
+ setup(name="bzr dump",
+ version="1.6.0dev0",
+ description="bzr dump.",
+ author="Robert Collins",
+ author_email="bazaar at lists.canonical.com",
+ license = "GNU GPL v2",
+ url="https://launchpad.net/bzr-dump",
+ packages=['bzrlib.plugins.dump',
+ 'bzrlib.plugins.dump.tests',
+ ],
+ package_dir={'bzrlib.plugins.dump': '.'},
+ cmdclass={'build_ext': build_ext_if_possible},
+ ext_modules=ext_modules,
+ )
More information about the bazaar-commits
mailing list