/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'),
32
                     commands.Option('lsprof-timed', help='Use lsprof'),
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
33
                     commands.Option('outfile', type=unicode,
34
                                     help='Write pseudo-knit to this file'),
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
35
                     commands.Option('memory', help='Use memory, not disk'),
0.9.20 by Aaron Bentley
Convert to a plugin
36
                     commands.Option('extract', help='test extract time'),
37
                     commands.Option('single', help='use a single parent'),
0.9.22 by Aaron Bentley
Fix restoration bug
38
                     commands.Option('verify', help='verify added texts'),
0.9.20 by Aaron Bentley
Convert to a plugin
39
                    ]
40
    hidden = True
41
42
    def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
0.9.22 by Aaron Bentley
Fix restoration bug
43
            lsprof_timed=False, dump=False, extract=False, single=False,
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
44
            verify=False, outfile=None, memory=False):
0.9.20 by Aaron Bentley
Convert to a plugin
45
        if file is None:
46
            wt, path = WorkingTree.open_containing('.')
47
            file_weave = wt.branch.repository.get_inventory_weave()
48
        else:
49
            wt, path = WorkingTree.open_containing(file)
50
            file_id = wt.path2id(path)
51
            bt = wt.branch.repository.revision_tree(wt.last_revision())
52
            file_weave = bt.get_weave(file_id)
53
        url = file_weave.transport.abspath(file_weave.filename)
54
        print >> sys.stderr, 'Importing: %s' % \
55
            urlutils.local_path_from_url(url)
56
        if sync_snapshots:
57
            print >> sys.stderr, 'Snapshots follow input'
58
        else:
59
            print >> sys.stderr, 'Snapshot interval: %d' % snapshot_interval
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
60
        if not memory:
61
            if outfile is None:
62
                filename = 'pknit'
63
            else:
64
                filename = outfile
65
            vf = MultiVersionedFile(filename, snapshot_interval)
66
        else:
67
            vf = MultiMemoryVersionedFile(snapshot_interval)
68
        vf.destroy()
0.9.20 by Aaron Bentley
Convert to a plugin
69
        snapshots = set(r for r in file_weave.versions() if
70
                        file_weave._index.get_method(r) == 'fulltext')
71
        if sync_snapshots:
72
            to_sync = snapshots
73
        else:
0.9.23 by Aaron Bentley
handle snapshots all at once
74
            to_sync = vf.select_snapshots(file_weave)
75
        print >> sys.stderr, "%d fulltexts" % len(snapshots)
0.9.25 by Aaron Bentley
More messy hacking
76
        print >> sys.stderr, "%d planned snapshots" % len(to_sync)
0.9.23 by Aaron Bentley
handle snapshots all at once
77
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
78
        try:
79
            vf.import_versionedfile(file_weave, to_sync, single_parent=single,
80
                                    verify=verify)
81
        except:
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
82
            vf.destroy()
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
83
            raise
84
        try:
85
            print >> sys.stderr, "%d actual snapshots" % len(to_sync)
86
            vf.clear_cache()
87
            if False:
88
                for revision_id in file_weave.get_ancestry(
89
                    [bt.inventory[file_id].revision]):
90
                    if vf.get_line_list([revision_id])[0] != \
91
                        file_weave.get_lines(revision_id):
92
                        open(revision_id + '.old', 'wb').writelines(
93
                            file_weave.get_lines(revision_id))
94
                        open(revision_id + '.new', 'wb').writelines(
95
                            vf.get_line_list(revision_id)[0])
96
            if extract:
97
                revisions = file_weave.versions()[-1:]
98
                if lsprof_timed:
99
                    from bzrlib.lsprof import profile
100
                    ret, stats = profile(vf.get_line_list, revisions)
101
                    stats.sort()
102
                    stats.pprint()
103
                start = time.clock()
104
                print >> sys.stderr, revisions[0]
105
                for x in range(1000):
106
                    vf.clear_cache()
107
                    vf.get_line_list(revisions)
108
                print >> sys.stderr, time.clock() - start
109
                start = time.clock()
110
                for x in range(1000):
111
                    file_weave.get_line_list(revisions)
112
                print >> sys.stderr, time.clock() - start
0.9.32 by Aaron Bentley
Allow specifying --outfile and --memory
113
            if memory and outfile is not None:
114
                outvf = MultiVersionedFile(outfile)
115
                for version_id in vf.versions():
116
                    outvf.add_diff(vf.get_diff(version_id), version_id,
117
                                   vf._parents[version_id])
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
118
        finally:
119
            if outfile is None:
0.9.31 by Aaron Bentley
Allow selecting MemoryVersionedFile from commandline
120
                vf.destroy()
0.9.20 by Aaron Bentley
Convert to a plugin
121
122
commands.register_command(cmd_mp_regen)
0.9.30 by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile
123
0.9.20 by Aaron Bentley
Convert to a plugin
124
def test_suite():
125
    from bzrlib.plugins.multiparent import test_multiparent
126
    return TestUtil.TestLoader().loadTestsFromModule(test_multiparent)