Merge lp:~jelmer/brz/cf-size into lp:brz

Proposed by Jelmer Vernooij on 2020-01-26
Status: Merged
Approved by: Jelmer Vernooij on 2020-01-26
Approved revision: 7466
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/cf-size
Merge into: lp:brz
Prerequisite: lp:~jelmer/brz/compress
Diff against target: 160 lines (+21/-7)
5 files modified
breezy/bzr/_groupcompress_py.py (+1/-2)
breezy/bzr/groupcompress.py (+10/-5)
breezy/bzr/knit.py (+1/-0)
breezy/bzr/versionedfile.py (+7/-0)
breezy/git/annotate.py (+2/-0)
To merge this branch: bzr merge lp:~jelmer/brz/cf-size
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve on 2020-01-26
Review via email: mp+378080@code.launchpad.net

This proposal supersedes a proposal from 2020-01-26.

Commit message

Add a size attribute to ContentFactory.

Description of the change

Add a size attribute to ContentFactory.

To post a comment you must log in.
Jelmer Vernooij (jelmer) : Posted in a previous version of this proposal
review: Approve
The Breezy Bot (the-breezy-bot) wrote : Posted in a previous version of this proposal
The Breezy Bot (the-breezy-bot) wrote : Posted in a previous version of this proposal
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/_groupcompress_py.py'
2--- breezy/bzr/_groupcompress_py.py 2020-01-25 22:05:40 +0000
3+++ breezy/bzr/_groupcompress_py.py 2020-01-26 04:33:55 +0000
4@@ -228,8 +228,7 @@
5 if block[-1] < min_match_bytes:
6 # This block may be a 'short' block, check
7 old_start, new_start, range_len = block
8- matched_bytes = sum(map(len,
9- lines[new_start:new_start + range_len]))
10+ matched_bytes = sum(map(len, lines[new_start:new_start + range_len]))
11 if matched_bytes < min_match_bytes:
12 block = None
13 if block is not None:
14
15=== modified file 'breezy/bzr/groupcompress.py'
16--- breezy/bzr/groupcompress.py 2020-01-26 04:33:55 +0000
17+++ breezy/bzr/groupcompress.py 2020-01-26 04:33:55 +0000
18@@ -441,6 +441,7 @@
19 self.key = key
20 self.parents = parents
21 self.sha1 = None
22+ self.size = None
23 # Note: This attribute coupled with Manager._factories creates a
24 # reference cycle. Perhaps we would rather use a weakref(), or
25 # find an appropriate time to release the ref. After the first
26@@ -569,7 +570,9 @@
27 end_point = 0
28 for factory in self._factories:
29 chunks = factory.get_bytes_as('chunked')
30- chunks_len = sum(map(len, chunks))
31+ chunks_len = factory.size
32+ if chunks_len is None:
33+ chunks_len = sum(map(len, chunks))
34 (found_sha1, start_point, end_point,
35 type) = compressor.compress(
36 factory.key, chunks, chunks_len, factory.sha1)
37@@ -1349,9 +1352,9 @@
38 # chunks in memory.
39 chunks = list(chunk_iter)
40 record = ChunkedContentFactory(key, parents, None, chunks)
41- sha1 = list(self._insert_record_stream(
42+ sha1, size = list(self._insert_record_stream(
43 [record], random_id=random_id, nostore_sha=nostore_sha))[0]
44- return sha1, sum(map(len, chunks)), None
45+ return sha1, size, None
46
47 def add_fallback_versioned_files(self, a_versioned_files):
48 """Add a source of texts for texts not present in this knit.
49@@ -1832,7 +1835,9 @@
50 adapter_key = record.storage_kind, 'chunked'
51 adapter = get_adapter(adapter_key)
52 chunks = adapter.get_bytes(record, 'chunked')
53- chunks_len = sum(map(len, chunks))
54+ chunks_len = record.size
55+ if chunks_len is None:
56+ chunks_len = sum(map(len, chunks))
57 if len(record.key) > 1:
58 prefix = record.key[0]
59 soft = (prefix == last_prefix)
60@@ -1873,7 +1878,7 @@
61 else:
62 key = record.key
63 self._unadded_refs[key] = record.parents
64- yield found_sha1
65+ yield found_sha1, chunks_len
66 as_st = static_tuple.StaticTuple.from_sequence
67 if record.parents is not None:
68 parents = as_st([as_st(p) for p in record.parents])
69
70=== modified file 'breezy/bzr/knit.py'
71--- breezy/bzr/knit.py 2020-01-25 14:39:08 +0000
72+++ breezy/bzr/knit.py 2020-01-26 04:33:55 +0000
73@@ -442,6 +442,7 @@
74 self.key = key
75 self.parents = parents
76 self.sha1 = None
77+ self.size = None
78 self._generator = generator
79 self.storage_kind = "knit-delta-closure"
80 if not first:
81
82=== modified file 'breezy/bzr/versionedfile.py'
83--- breezy/bzr/versionedfile.py 2020-01-25 15:55:41 +0000
84+++ breezy/bzr/versionedfile.py 2020-01-26 04:33:55 +0000
85@@ -75,6 +75,7 @@
86 """Abstract interface for insertion and retrieval from a VersionedFile.
87
88 :ivar sha1: None, or the sha1 of the content fulltext.
89+ :ivar size: None, or the size of the content fulltext.
90 :ivar storage_kind: The native storage kind of this factory. One of
91 'mpdiff', 'knit-annotated-ft', 'knit-annotated-delta', 'knit-ft',
92 'knit-delta', 'fulltext', 'knit-annotated-ft-gz',
93@@ -89,6 +90,7 @@
94 def __init__(self):
95 """Create a ContentFactory."""
96 self.sha1 = None
97+ self.size = None
98 self.storage_kind = None
99 self.key = None
100 self.parents = None
101@@ -102,6 +104,7 @@
102 satisfies this, as does a list of lines.
103
104 :ivar sha1: None, or the sha1 of the content fulltext.
105+ :ivar size: None, or the size of the content fulltext.
106 :ivar storage_kind: The native storage kind of this factory. Always
107 'chunked'
108 :ivar key: The key of this content. Each key is a tuple with a single
109@@ -115,6 +118,7 @@
110 def __init__(self, key, parents, sha1, chunks, chunks_are_lines=None):
111 """Create a ContentFactory."""
112 self.sha1 = sha1
113+ self.size = sum(map(len, chunks))
114 self.storage_kind = 'chunked'
115 self.key = key
116 self.parents = parents
117@@ -153,6 +157,7 @@
118 def __init__(self, key, parents, sha1, text):
119 """Create a ContentFactory."""
120 self.sha1 = sha1
121+ self.size = len(text)
122 self.storage_kind = 'fulltext'
123 self.key = key
124 self.parents = parents
125@@ -181,6 +186,7 @@
126 self.file = fileobj
127 self.storage_kind = 'file'
128 self._sha1 = None
129+ self._size = None
130
131 @property
132 def sha1(self):
133@@ -214,6 +220,7 @@
134 def __init__(self, key):
135 """Create a ContentFactory."""
136 self.sha1 = None
137+ self.size = None
138 self.storage_kind = 'absent'
139 self.key = key
140 self.parents = None
141
142=== modified file 'breezy/git/annotate.py'
143--- breezy/git/annotate.py 2020-01-25 14:07:41 +0000
144+++ breezy/git/annotate.py 2020-01-26 04:33:55 +0000
145@@ -56,6 +56,7 @@
146 self.storage_kind = 'git-blob'
147 self.parents = None
148 self.blob_id = blob_id
149+ self.size = None
150
151 def get_bytes_as(self, storage_kind):
152 if storage_kind == 'fulltext':
153@@ -87,6 +88,7 @@
154 self.key = (path, revision)
155 self.storage_kind = 'absent'
156 self.parents = None
157+ self.size = None
158
159 def get_bytes_as(self, storage_kind):
160 raise ValueError

Subscribers

People subscribed via source and target branches