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