~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2007-04-13 20:34:16 UTC
  • mto: (2520.4.1 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070413203416-7jeoifz1gq41ashn
Implement save, load, snapshot-by-size

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
                                     help='Snapshots follow source'),
30
30
                     commands.Option('snapshot-interval', type=int,
31
31
                                     help='take snapshots every x revisions'),
32
 
                     commands.Option('lsprof-timed', help='Use lsprof'),
33
32
                     commands.Option('outfile', type=unicode,
34
33
                                     help='Write pseudo-knit to this file'),
35
34
                     commands.Option('memory', help='Use memory, not disk'),
37
36
                     commands.Option('single', help='use a single parent'),
38
37
                     commands.Option('verify', help='verify added texts'),
39
38
                     commands.Option('cache', help='Aggresively cache'),
 
39
                     commands.Option('size', help='Aggressive size'),
40
40
                    ]
41
41
    hidden = True
42
42
 
43
43
    def run(self, file=None, sync_snapshots=False, snapshot_interval=26,
44
44
            lsprof_timed=False, dump=False, extract=False, single=False,
45
 
            verify=False, outfile=None, memory=False, cache=False):
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)
 
45
            verify=False, outfile=None, memory=False, cache=False,
 
46
            size=False):
 
47
        file_weave = get_file_weave(file)
54
48
        url = file_weave.transport.abspath(file_weave.filename)
 
49
        if size:
 
50
            assert memory
55
51
        print >> sys.stderr, 'Importing: %s' % \
56
52
            urlutils.local_path_from_url(url)
57
53
        if sync_snapshots:
71
67
                        file_weave._index.get_method(r) == 'fulltext')
72
68
        if sync_snapshots:
73
69
            to_sync = snapshots
 
70
        elif size:
 
71
            to_sync = set()
74
72
        else:
75
73
            to_sync = vf.select_snapshots(file_weave)
76
74
        print >> sys.stderr, "%d fulltexts" % len(snapshots)
79
77
        try:
80
78
            vf.import_versionedfile(file_weave, to_sync, single_parent=single,
81
79
                                    verify=verify, no_cache=not cache)
 
80
            if size:
 
81
                snapshots = vf.select_by_size(len(snapshots))
 
82
                for version_id in snapshots:
 
83
                    vf.make_snapshot(version_id)
82
84
        except:
83
85
            vf.destroy()
84
86
            raise
85
87
        try:
86
 
            print >> sys.stderr, "%d actual snapshots" % len(to_sync)
 
88
            print >> sys.stderr, "%d actual snapshots" % len(vf._snapshots)
87
89
            if not cache:
88
90
                vf.clear_cache()
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
115
 
            if memory and outfile is not None:
116
 
                outvf = MultiVersionedFile(outfile)
 
91
            if memory:
 
92
                if outfile is not None:
 
93
                    vf_file = MultiVersionedFile(outfile)
117
94
                for version_id in vf.versions():
118
 
                    outvf.add_diff(vf.get_diff(version_id), version_id,
119
 
                                   vf._parents[version_id])
 
95
                    vf_file.add_diff(vf.get_diff(version_id), version_id,
 
96
                                     vf._parents[version_id])
 
97
            else:
 
98
                vf_file = vf
120
99
        finally:
121
100
            if outfile is None:
122
101
                vf.destroy()
 
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
 
123
155
 
124
156
commands.register_command(cmd_mp_regen)
 
157
commands.register_command(cmd_mp_extract)
125
158
 
126
159
def test_suite():
127
160
    from bzrlib.plugins.multiparent import test_multiparent