1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/bin/env python2.4
from itertools import izip
from StringIO import StringIO
import sys
import time
from bzrlib.tuned_gzip import GzipFile
from bzrlib.workingtree import WorkingTree
from multiparent import MultiVersionedFile
single_parent = False
if len(sys.argv) > 1 and len(sys.argv) < 4:
wt, path = WorkingTree.open_containing(sys.argv[-1])
if len(sys.argv) == 3:
assert sys.argv[1] == '--single'
single_parent = True
else:
print >> sys.stderr, 'Usage: mpknit [--single] FILENAME'
sys.exit(3)
bt = wt.branch.repository.revision_tree(wt.last_revision())
file_id = wt.path2id(path)
file_weave = wt.branch.repository.get_inventory_weave()
#file_weave = bt.get_weave(file_id)
file_weave.enable_cache()
revisions = set(file_weave.versions())
ft_set = set(r for r in revisions if file_weave._index.get_method(r)
== 'fulltext')
vf = MultiVersionedFile(None)
#files = {}
#for version_id in revisions:
# lines = [a + ' ' + l for a, l in file_weave.annotate_iter(version_id)]
# files[version_id] = lines
#files = dict(izip(ancestry, file_weave.get_line_list(ancestry)))
total = len(revisions)
while len(revisions) > 0:
added = set()
for revision in revisions:
parents = file_weave.get_parents(revision)
if [p for p in parents if p not in vf._diffs] != []:
continue
lines = file_weave.get_lines(revision)
vf.add_version(lines, revision, parents,
force_snapshot=(revision in ft_set))
added.add(revision)
vf.clear_cache()
revisions = [r for r in revisions if r not in added]
print >> sys.stderr, "%.1f %%" % ((((total - len(revisions)) * 100.0)
/ total))
print >> sys.stderr, file_weave
print >> sys.stderr, "%d fulltexts" % len(ft_set)
print >> sys.stderr, "%d snapshots" % len(vf._snapshots)
vf.clear_cache()
if False:
for revision_id in file_weave.get_ancestry(
[bt.inventory[file_id].revision]):
if vf.get_line_list([revision_id])[0] != \
file_weave.get_lines(revision_id):
open(revision_id + '.old', 'wb').writelines(
file_weave.get_lines(revision_id))
open(revision_id + '.new', 'wb').writelines(
vf.get_line_list(revision_id)[0])
if True:
revisions = file_weave.get_ancestry(
[bt.inventory[file_id].revision])[-1:]
from bzrlib.lsprof import profile
ret, stats = profile(vf.get_line_list, revisions)
stats.sort()
stats.pprint()
start = time.clock()
print revisions
for x in range(1000):
vf.clear_cache()
vf.get_line_list(revisions)
print time.clock() - start
start = time.clock()
for x in range(1000):
file_weave.get_line_list(revisions)
print time.clock() - start
if False:
revisions = file_weave.versions()
for revision, diff in vf._diffs.iteritems():
sio = StringIO()
data_file = GzipFile(None, mode='wb', fileobj=sio)
print >> data_file, 'version %s' % revision
data_file.writelines(diff.to_patch())
data_file.close()
sys.stdout.write(sio.getvalue())
|