/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
0.9.20 by Aaron Bentley
Convert to a plugin
3
lazy_import(globals(), """
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
4
import (
5
        errno,
6
        os,
7
        sys,
8
        time,
9
        )
10
11
from bzrlib import (
12
    commands,
13
    urlutils
14
    )
0.9.12 by Aaron Bentley
Make benchmarks for mp
15
from bzrlib.workingtree import WorkingTree
0.9.20 by Aaron Bentley
Convert to a plugin
16
from bzrlib.tests import TestUtil
17
0.9.25 by Aaron Bentley
More messy hacking
18
from bzrlib.plugins.multiparent.multiparent import (
19
    MultiVersionedFile,
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
20
    MultiMemoryVersionedFile,
0.9.25 by Aaron Bentley
More messy hacking
21
    )
0.9.20 by Aaron Bentley
Convert to a plugin
22
""")
23
24
class cmd_mp_regen(commands.Command):
25
    """Generate a multiparent versionedfile"""
26
27
    takes_args = ['file?']
28
    takes_options = [commands.Option('sync-snapshots',
29
                                     help='Snapshots follow source'),
30
                     commands.Option('snapshot-interval', type=int,
31
                                     help='take snapshots every x revisions'),
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
32
                     commands.Option('outfile', type=unicode,
33
                                     help='Write pseudo-knit to this file'),
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
34
                     commands.Option('memory', help='Use memory, not disk'),
0.9.20 by Aaron Bentley
Convert to a plugin
35
                     commands.Option('extract', help='test extract time'),
36
                     commands.Option('single', help='use a single parent'),
0.9.22 by Aaron Bentley
Fix restoration bug
37
                     commands.Option('verify', help='verify added texts'),
0.9.33 by Aaron Bentley
Enable caching commandline param
38
                     commands.Option('cache', help='Aggresively cache'),
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
39
                     commands.Option('size', help='Aggressive size'),
0.9.20 by Aaron Bentley
Convert to a plugin
40
                    ]
41
    hidden = True
42
43
    def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
0.9.22 by Aaron Bentley
Fix restoration bug
44
            lsprof_timed=False, dump=False, extract=False, single=False,
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
45
            verify=False, outfile=None, memory=False, cache=False,
46
            size=False):
47
        file_weave = get_file_weave(file)
0.9.20 by Aaron Bentley
Convert to a plugin
48
        url = file_weave.transport.abspath(file_weave.filename)
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
49
        if size:
50
            assert memory
0.9.20 by Aaron Bentley
Convert to a plugin
51
        print >> sys.stderr, 'Importing: %s' % \
52
            urlutils.local_path_from_url(url)
53
        if sync_snapshots:
54
            print >> sys.stderr, 'Snapshots follow input'
55
        else:
56
            print >> sys.stderr, 'Snapshot interval: %d' % snapshot_interval
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
57
        if not memory:
58
            if outfile is None:
59
                filename = 'pknit'
60
            else:
61
                filename = outfile
62
            vf = MultiVersionedFile(filename, snapshot_interval)
63
        else:
64
            vf = MultiMemoryVersionedFile(snapshot_interval)
65
        vf.destroy()
0.9.20 by Aaron Bentley
Convert to a plugin
66
        snapshots = set(r for r in file_weave.versions() if
67
                        file_weave._index.get_method(r) == 'fulltext')
68
        if sync_snapshots:
69
            to_sync = snapshots
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
70
        elif size:
71
            to_sync = set()
0.9.20 by Aaron Bentley
Convert to a plugin
72
        else:
0.9.23 by Aaron Bentley
handle snapshots all at once
73
            to_sync = vf.select_snapshots(file_weave)
74
        print >> sys.stderr, "%d fulltexts" % len(snapshots)
0.9.25 by Aaron Bentley
More messy hacking
75
        print >> sys.stderr, "%d planned snapshots" % len(to_sync)
0.9.23 by Aaron Bentley
handle snapshots all at once
76
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
77
        try:
78
            vf.import_versionedfile(file_weave, to_sync, single_parent=single,
0.9.33 by Aaron Bentley
Enable caching commandline param
79
                                    verify=verify, no_cache=not cache)
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
80
            if size:
81
                snapshots = vf.select_by_size(len(snapshots))
82
                for version_id in snapshots:
83
                    vf.make_snapshot(version_id)
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
84
        except:
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
85
            vf.destroy()
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
86
            raise
87
        try:
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
88
            print >> sys.stderr, "%d actual snapshots" % len(vf._snapshots)
0.9.33 by Aaron Bentley
Enable caching commandline param
89
            if not cache:
90
                vf.clear_cache()
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
91
            if memory:
92
                if outfile is not None:
93
                    vf_file = MultiVersionedFile(outfile)
0.9.32 by Aaron Bentley
Allow specifying --outfile and --memory
94
                for version_id in vf.versions():
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
95
                    vf_file.add_diff(vf.get_diff(version_id), version_id,
96
                                     vf._parents[version_id])
97
            else:
98
                vf_file = vf
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
99
        finally:
100
            if outfile is None:
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
101
                vf.destroy()
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
102
            else:
103
                vf_file.save()
104
105
class cmd_mp_extract(commands.Command):
106
107
    takes_options = [
108
        commands.Option('lsprof-timed', help='Use lsprof'),
109
        commands.Option('parallel', help='extract multiple versions at once'),
110
        commands.Option('count', help='Number of cycles to do', type=int),
111
        ]
112
113
    takes_args = ['filename', 'vfile?']
114
115
    def run(self, filename, vfile=None, lsprof_timed=False, count=1000,
116
            parallel=False):
117
        vf = MultiVersionedFile(filename)
118
        vf.load()
119
        revisions = list(vf.versions())
120
        revisions = revisions[-count:]
121
        print 'Testing extract time of %d revisions' % len(revisions)
122
        if parallel:
123
            revisions_list = [revisions]
124
        else:
125
            revisions_list = [[r] for r in revisions]
126
        start = time.clock()
127
        for revisions in revisions_list:
128
            vf = MultiVersionedFile(filename)
129
            vf.load()
130
            vf.get_line_list(revisions)
131
        print >> sys.stderr, time.clock() - start
132
        if lsprof_timed:
133
            from bzrlib.lsprof import profile
134
            vf.clear_cache()
135
            ret, stats = profile(vf.get_line_list, revisions_list[-1][-1])
136
            stats.sort()
137
            stats.pprint()
138
        start = time.clock()
139
        for revisions in revisions_list:
140
            file_weave = get_file_weave(vfile)
141
            file_weave.get_line_list(revisions)
142
        print >> sys.stderr, time.clock() - start
143
144
145
def get_file_weave(filename=None, wt=None):
146
    if filename is None:
147
        wt, path = WorkingTree.open_containing('.')
148
        return wt.branch.repository.get_inventory_weave()
149
    else:
150
        wt, path = WorkingTree.open_containing(filename)
151
        file_id = wt.path2id(path)
152
        bt = wt.branch.repository.revision_tree(wt.last_revision())
153
        return bt.get_weave(file_id)
154
0.9.20 by Aaron Bentley
Convert to a plugin
155
156
commands.register_command(cmd_mp_regen)
0.9.34 by Aaron Bentley
Implement save, load, snapshot-by-size
157
commands.register_command(cmd_mp_extract)
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
158
0.9.20 by Aaron Bentley
Convert to a plugin
159
def test_suite():
160
    from bzrlib.plugins.multiparent import test_multiparent
161
    return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)