/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:
0.9.23 by Aaron Bentley
handle snapshots all at once
58
            to_sync = vf.select_snapshots(file_weave)
59
        print >> sys.stderr, "%d fulltexts" % len(snapshots)
60
        print >> sys.stderr, "%d snapshots" % len(to_sync)
61
0.9.22 by Aaron Bentley
Fix restoration bug
62
        vf.import_versionedfile(file_weave, to_sync, single_parent=single,
63
                                verify=verify)
0.9.12 by Aaron Bentley
Make benchmarks for mp
64
        vf.clear_cache()
0.9.20 by Aaron Bentley
Convert to a plugin
65
        if False:
66
            for revision_id in file_weave.get_ancestry(
67
                [bt.inventory[file_id].revision]):
68
                if vf.get_line_list([revision_id])[0] != \
69
                    file_weave.get_lines(revision_id):
70
                    open(revision_id + '.old', 'wb').writelines(
71
                        file_weave.get_lines(revision_id))
72
                    open(revision_id + '.new', 'wb').writelines(
73
                        vf.get_line_list(revision_id)[0])
74
        if extract:
75
            revisions = file_weave.versions()[-1:]
76
            if lsprof_timed:
77
                from bzrlib.lsprof import profile
78
                ret, stats = profile(vf.get_line_list, revisions)
79
                stats.sort()
80
                stats.pprint()
81
            start = time.clock()
82
            print >> sys.stderr, revisions[0]
83
            for x in range(1000):
84
                vf.clear_cache()
85
                vf.get_line_list(revisions)
86
            print >> sys.stderr, time.clock() - start
87
            start = time.clock()
88
            for x in range(1000):
89
                file_weave.get_line_list(revisions)
90
            print >> sys.stderr, time.clock() - start
91
        if dump:
92
            revisions = file_weave.versions()
93
94
            for revision, diff in vf._diffs.iteritems():
95
                sio = StringIO()
96
                data_file = GzipFile(None, mode='wb', fileobj=sio)
97
                print >> data_file, 'version %s' % revision
98
                data_file.writelines(diff.to_patch())
99
                data_file.close()
100
                sys.stdout.write(sio.getvalue())
101
102
commands.register_command(cmd_mp_regen)
103
def test_suite():
104
    from bzrlib.plugins.multiparent import test_multiparent
105
    return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)