1
"""Implementation of multiparent diffs for versionedfile-like storage
3
Provides mp-regen and mp-extract commands.
4
Focus is on comparing size/performance to knits.
7
from bzrlib.lazy_import import lazy_import
9
lazy_import(globals(), """
21
from bzrlib.workingtree import WorkingTree
22
from bzrlib.tests import TestUtil
24
from bzrlib.plugins.multiparent.multiparent import (
26
MultiMemoryVersionedFile,
30
class cmd_mp_regen(commands.Command):
31
"""Generate a multiparent versionedfile"""
33
takes_args = ['file?']
34
takes_options = [commands.Option('sync-snapshots',
35
help='Snapshots follow source'),
36
commands.Option('snapshot-interval', type=int,
37
help='take snapshots every x revisions'),
38
commands.Option('outfile', type=unicode,
39
help='Write pseudo-knit to this file'),
40
commands.Option('memory', help='Use memory, not disk'),
41
commands.Option('extract', help='test extract time'),
42
commands.Option('single', help='use a single parent'),
43
commands.Option('verify', help='verify added texts'),
44
commands.Option('cache', help='Aggresively cache'),
45
commands.Option('size', help='Aggressive size'),
46
commands.Option('build', help='Aggressive build'),
50
def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
51
lsprof_timed=False, dump=False, extract=False, single=False,
52
verify=False, outfile=None, memory=False, cache=False,
53
size=False, build=False):
54
file_weave = get_file_weave(file)
55
url = file_weave.transport.abspath(file_weave.filename)
56
print >> sys.stderr, 'Importing: %s' % \
57
urlutils.local_path_from_url(url)
59
print >> sys.stderr, 'Snapshots follow input'
61
print >> sys.stderr, 'Snapshot interval: %d' % snapshot_interval
67
vf = MultiVersionedFile(filename, snapshot_interval)
69
vf = MultiMemoryVersionedFile(snapshot_interval)
71
old_snapshots = set(r for r in file_weave.versions() if
72
file_weave._index.get_method(r) == 'fulltext')
74
to_sync = old_snapshots
79
to_sync = vf.select_snapshots(file_weave)
80
print >> sys.stderr, "%d fulltext(s)" % len(old_snapshots)
81
print >> sys.stderr, "%d planned snapshots" % len(to_sync)
84
vf.import_versionedfile(file_weave, to_sync, single_parent=single,
85
verify=verify, no_cache=not cache)
87
snapshots = vf.select_by_size(len(old_snapshots))
88
for version_id in snapshots:
89
vf.make_snapshot(version_id)
91
ranking = vf.get_build_ranking()
92
snapshots = ranking[:len(old_snapshots) -\
94
for version_id in snapshots:
95
vf.make_snapshot(version_id)
100
print >> sys.stderr, "%d actual snapshots" % len(vf._snapshots)
104
if outfile is not None:
105
vf_file = MultiVersionedFile(outfile)
106
vf_file.import_diffs(vf)
115
class cmd_mp_extract(commands.Command):
116
"""Test extraction time multiparent knits"""
119
commands.Option('lsprof-timed', help='Use lsprof'),
120
commands.Option('parallel', help='extract multiple versions at once'),
121
commands.Option('count', help='Number of cycles to do', type=int),
124
takes_args = ['filename', 'vfile?']
126
def run(self, filename, vfile=None, lsprof_timed=False, count=1000,
128
vf = MultiVersionedFile(filename)
130
snapshots = [r for r in vf.versions() if vf.get_diff(r).is_snapshot()]
131
print '%d snapshots' % len(snapshots)
132
revisions = list(vf.versions())
133
revisions = revisions[-count:]
134
print 'Testing extract time of %d revisions' % len(revisions)
136
revisions_list = [revisions]
138
revisions_list = [[r] for r in revisions]
140
for revisions in revisions_list:
141
vf = MultiVersionedFile(filename)
143
vf.get_line_list(revisions)
144
print >> sys.stderr, time.clock() - start
146
from bzrlib.lsprof import profile
148
ret, stats = profile(vf.get_line_list, revisions_list[-1][-1])
152
for revisions in revisions_list:
153
file_weave = get_file_weave(vfile)
154
file_weave.get_line_list(revisions)
155
print >> sys.stderr, time.clock() - start
158
def get_file_weave(filename=None, wt=None):
160
wt, path = WorkingTree.open_containing('.')
161
return wt.branch.repository.get_inventory_weave()
163
wt, path = WorkingTree.open_containing(filename)
164
file_id = wt.path2id(path)
165
bt = wt.branch.repository.revision_tree(wt.last_revision())
166
return bt.get_weave(file_id)
169
commands.register_command(cmd_mp_regen)
170
commands.register_command(cmd_mp_extract)
173
from bzrlib.plugins.multiparent import test_multiparent
174
return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)