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