1
#!/usr/bin/env python2.4
1
from bzrlib.lazy_import import lazy_import
2
2
from itertools import izip
3
3
from StringIO import StringIO
7
lazy_import(globals(), """
8
from bzrlib import commands
7
9
from bzrlib.tuned_gzip import GzipFile
8
10
from bzrlib.workingtree import WorkingTree
10
from multiparent import MultiVersionedFile
12
if len(sys.argv) > 1 and len(sys.argv) < 4:
13
wt, path = WorkingTree.open_containing(sys.argv[-1])
14
if len(sys.argv) == 3:
15
assert sys.argv[1] == '--single'
18
print >> sys.stderr, 'Usage: mpknit [--single] FILENAME'
21
bt = wt.branch.repository.revision_tree(wt.last_revision())
22
file_id = wt.path2id(path)
23
file_weave = wt.branch.repository.get_inventory_weave()
24
#file_weave = bt.get_weave(file_id)
25
#file_weave.enable_cache()
26
vf = MultiVersionedFile(25)
27
ft_set = set(r for r in file_weave.versions() if
28
file_weave._index.get_method(r) == 'fulltext')
29
vf.import_versionedfile(file_weave)
30
print >> sys.stderr, file_weave
31
print >> sys.stderr, "%d fulltexts" % len(ft_set)
32
print >> sys.stderr, "%d snapshots" % len(vf._snapshots)
35
for revision_id in file_weave.get_ancestry(
36
[bt.inventory[file_id].revision]):
37
if vf.get_line_list([revision_id])[0] != \
38
file_weave.get_lines(revision_id):
39
open(revision_id + '.old', 'wb').writelines(
40
file_weave.get_lines(revision_id))
41
open(revision_id + '.new', 'wb').writelines(
42
vf.get_line_list(revision_id)[0])
44
revisions = file_weave.get_ancestry(
45
[bt.inventory[file_id].revision])[-1:]
46
from bzrlib.lsprof import profile
47
ret, stats = profile(vf.get_line_list, revisions)
11
from bzrlib.tests import TestUtil
12
from bzrlib import urlutils
14
from bzrlib.plugins.multiparent.multiparent import MultiVersionedFile
17
class cmd_mp_regen(commands.Command):
18
"""Generate a multiparent versionedfile"""
20
takes_args = ['file?']
21
takes_options = [commands.Option('sync-snapshots',
22
help='Snapshots follow source'),
23
commands.Option('snapshot-interval', type=int,
24
help='take snapshots every x revisions'),
25
commands.Option('lsprof-timed', help='Use lsprof'),
26
commands.Option('dump',
27
help='dump pseudo-knit to stdout'),
28
commands.Option('extract', help='test extract time'),
29
commands.Option('single', help='use a single parent'),
33
def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
34
lsprof_timed=False, dump=False, extract=False, single=False):
36
wt, path = WorkingTree.open_containing('.')
37
file_weave = wt.branch.repository.get_inventory_weave()
39
wt, path = WorkingTree.open_containing(file)
40
file_id = wt.path2id(path)
41
bt = wt.branch.repository.revision_tree(wt.last_revision())
42
file_weave = bt.get_weave(file_id)
43
url = file_weave.transport.abspath(file_weave.filename)
44
print >> sys.stderr, 'Importing: %s' % \
45
urlutils.local_path_from_url(url)
47
print >> sys.stderr, 'Snapshots follow input'
49
print >> sys.stderr, 'Snapshot interval: %d' % snapshot_interval
50
vf = MultiVersionedFile(snapshot_interval)
51
snapshots = set(r for r in file_weave.versions() if
52
file_weave._index.get_method(r) == 'fulltext')
57
vf.import_versionedfile(file_weave, to_sync, single_parent=single)
58
print >> sys.stderr, "%d fulltexts" % len(snapshots)
59
print >> sys.stderr, "%d snapshots" % len(vf._snapshots)
54
vf.get_line_list(revisions)
55
print time.clock() - start
58
file_weave.get_line_list(revisions)
59
print time.clock() - start
61
revisions = file_weave.versions()
63
for revision, diff in vf._diffs.iteritems():
65
data_file = GzipFile(None, mode='wb', fileobj=sio)
66
print >> data_file, 'version %s' % revision
67
data_file.writelines(diff.to_patch())
69
sys.stdout.write(sio.getvalue())
62
for revision_id in file_weave.get_ancestry(
63
[bt.inventory[file_id].revision]):
64
if vf.get_line_list([revision_id])[0] != \
65
file_weave.get_lines(revision_id):
66
open(revision_id + '.old', 'wb').writelines(
67
file_weave.get_lines(revision_id))
68
open(revision_id + '.new', 'wb').writelines(
69
vf.get_line_list(revision_id)[0])
71
revisions = file_weave.versions()[-1:]
73
from bzrlib.lsprof import profile
74
ret, stats = profile(vf.get_line_list, revisions)
78
print >> sys.stderr, revisions[0]
81
vf.get_line_list(revisions)
82
print >> sys.stderr, time.clock() - start
85
file_weave.get_line_list(revisions)
86
print >> sys.stderr, time.clock() - start
88
revisions = file_weave.versions()
90
for revision, diff in vf._diffs.iteritems():
92
data_file = GzipFile(None, mode='wb', fileobj=sio)
93
print >> data_file, 'version %s' % revision
94
data_file.writelines(diff.to_patch())
96
sys.stdout.write(sio.getvalue())
98
commands.register_command(cmd_mp_regen)
100
from bzrlib.plugins.multiparent import test_multiparent
101
return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)