~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_pyx.pyx

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
            self._index = NULL
119
119
        safe_free(<void **>&self._source_infos)
120
120
 
 
121
    def _has_index(self):
 
122
        return (self._index != NULL)
 
123
 
121
124
    def add_delta_source(self, delta, unadded_bytes):
122
125
        """Add a new delta to the source texts.
123
126
 
171
174
        source_location = len(self._sources)
172
175
        if source_location >= self._max_num_sources:
173
176
            self._expand_sources()
 
177
        if source_location != 0 and self._index == NULL:
 
178
            # We were lazy about populating the index, create it now
 
179
            self._populate_first_index()
174
180
        self._sources.append(source)
175
181
        c_source = PyString_AS_STRING(source)
176
182
        c_source_size = PyString_GET_SIZE(source)
179
185
        src.size = c_source_size
180
186
 
181
187
        src.agg_offset = self._source_offset + unadded_bytes
182
 
        index = create_delta_index(src, self._index)
183
188
        self._source_offset = src.agg_offset + src.size
184
 
        if index != NULL:
185
 
            free_delta_index(self._index)
186
 
            self._index = index
 
189
        # We delay creating the index on the first insert
 
190
        if source_location != 0:
 
191
            index = create_delta_index(src, self._index)
 
192
            if index != NULL:
 
193
                free_delta_index(self._index)
 
194
                self._index = index
 
195
 
 
196
    cdef _populate_first_index(self):
 
197
        cdef delta_index *index
 
198
        if len(self._sources) != 1 or self._index != NULL:
 
199
            raise AssertionError('_populate_first_index should only be'
 
200
                ' called when we have a single source and no index yet')
 
201
 
 
202
        # We know that self._index is already NULL, so whatever
 
203
        # create_delta_index returns is fine
 
204
        self._index = create_delta_index(&self._source_infos[0], NULL)
 
205
        assert self._index != NULL
187
206
 
188
207
    cdef _expand_sources(self):
189
208
        raise RuntimeError('if we move self._source_infos, then we need to'
201
220
        cdef unsigned long delta_size
202
221
 
203
222
        if self._index == NULL:
204
 
            return None
 
223
            if len(self._sources) == 0:
 
224
                return None
 
225
            # We were just lazy about generating the index
 
226
            self._populate_first_index()
205
227
 
206
228
        if not PyString_CheckExact(target_bytes):
207
229
            raise TypeError('target is not a str')