/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.9.20 by Aaron Bentley
Convert to a plugin
1
from bzrlib.lazy_import import lazy_import
0.9.12 by Aaron Bentley
Make benchmarks for mp
2
from itertools import izip
0.9.15 by Aaron Bentley
Make mpregen output a psuedo-knit
3
from StringIO import StringIO
0.9.12 by Aaron Bentley
Make benchmarks for mp
4
import sys
5
import time
6
0.9.20 by Aaron Bentley
Convert to a plugin
7
lazy_import(globals(), """
8
from bzrlib import commands
0.9.15 by Aaron Bentley
Make mpregen output a psuedo-knit
9
from bzrlib.tuned_gzip import GzipFile
0.9.12 by Aaron Bentley
Make benchmarks for mp
10
from bzrlib.workingtree import WorkingTree
0.9.20 by Aaron Bentley
Convert to a plugin
11
from bzrlib.tests import TestUtil
12
from bzrlib import urlutils
13
14
from bzrlib.plugins.multiparent.multiparent import MultiVersionedFile
15
""")
16
17
class cmd_mp_regen(commands.Command):
18
    """Generate a multiparent versionedfile"""
19
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'),
0.9.22 by Aaron Bentley
Fix restoration bug
30
                     commands.Option('verify', help='verify added texts'),
0.9.20 by Aaron Bentley
Convert to a plugin
31
                    ]
32
    hidden = True
33
34
    def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
0.9.22 by Aaron Bentley
Fix restoration bug
35
            lsprof_timed=False, dump=False, extract=False, single=False,
36
            verify=False):
0.9.20 by Aaron Bentley
Convert to a plugin
37
        if file is None:
38
            wt, path = WorkingTree.open_containing('.')
39
            file_weave = wt.branch.repository.get_inventory_weave()
40
        else:
41
            wt, path = WorkingTree.open_containing(file)
42
            file_id = wt.path2id(path)
43
            bt = wt.branch.repository.revision_tree(wt.last_revision())
44
            file_weave = bt.get_weave(file_id)
45
        url = file_weave.transport.abspath(file_weave.filename)
46
        print >> sys.stderr, 'Importing: %s' % \
47
            urlutils.local_path_from_url(url)
48
        if sync_snapshots:
49
            print >> sys.stderr, 'Snapshots follow input'
50
        else:
51
            print >> sys.stderr, 'Snapshot interval: %d' % snapshot_interval
52
        vf = MultiVersionedFile(snapshot_interval)
53
        snapshots = set(r for r in file_weave.versions() if
54
                        file_weave._index.get_method(r) == 'fulltext')
55
        if sync_snapshots:
56
            to_sync = snapshots
57
        else:
58
            to_sync = None
0.9.22 by Aaron Bentley
Fix restoration bug
59
        vf.import_versionedfile(file_weave, to_sync, single_parent=single,
60
                                verify=verify)
0.9.20 by Aaron Bentley
Convert to a plugin
61
        print >> sys.stderr, "%d fulltexts" % len(snapshots)
62
        print >> sys.stderr, "%d snapshots" % len(vf._snapshots)
0.9.12 by Aaron Bentley
Make benchmarks for mp
63
        vf.clear_cache()
0.9.20 by Aaron Bentley
Convert to a plugin
64
        if False:
65
            for revision_id in file_weave.get_ancestry(
66
                [bt.inventory[file_id].revision]):
67
                if vf.get_line_list([revision_id])[0] != \
68
                    file_weave.get_lines(revision_id):
69
                    open(revision_id + '.old', 'wb').writelines(
70
                        file_weave.get_lines(revision_id))
71
                    open(revision_id + '.new', 'wb').writelines(
72
                        vf.get_line_list(revision_id)[0])
73
        if extract:
74
            revisions = file_weave.versions()[-1:]
75
            if lsprof_timed:
76
                from bzrlib.lsprof import profile
77
                ret, stats = profile(vf.get_line_list, revisions)
78
                stats.sort()
79
                stats.pprint()
80
            start = time.clock()
81
            print >> sys.stderr, revisions[0]
82
            for x in range(1000):
83
                vf.clear_cache()
84
                vf.get_line_list(revisions)
85
            print >> sys.stderr, time.clock() - start
86
            start = time.clock()
87
            for x in range(1000):
88
                file_weave.get_line_list(revisions)
89
            print >> sys.stderr, time.clock() - start
90
        if dump:
91
            revisions = file_weave.versions()
92
93
            for revision, diff in vf._diffs.iteritems():
94
                sio = StringIO()
95
                data_file = GzipFile(None, mode='wb', fileobj=sio)
96
                print >> data_file, 'version %s' % revision
97
                data_file.writelines(diff.to_patch())
98
                data_file.close()
99
                sys.stdout.write(sio.getvalue())
100
101
commands.register_command(cmd_mp_regen)
102
def test_suite():
103
    from bzrlib.plugins.multiparent import test_multiparent
104
    return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)