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