/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
1297
1297
        :param index_builder_class: The index builder class to use.
1298
1298
        :param index_class: The index class to use.
1299
1299
        """
 
1300
        # XXX: This should call self.reset()
1300
1301
        self.repo = repo
1301
1302
        self.transport = transport
1302
1303
        self._index_transport = index_transport
1307
1308
        self._suffix_offsets = {'.rix': 0, '.iix': 1, '.tix': 2, '.six': 3}
1308
1309
        self.packs = []
1309
1310
        # name:Pack mapping
 
1311
        self._names = None
1310
1312
        self._packs_by_name = {}
1311
1313
        # the previous pack-names content
1312
1314
        self._packs_at_load = None
1527
1529
        return [[final_rev_count, final_pack_list]]
1528
1530
 
1529
1531
    def ensure_loaded(self):
 
1532
        """Ensure we have read names from disk.
 
1533
 
 
1534
        :return: True if the disk names had not been previously read.
 
1535
        """
1530
1536
        # NB: if you see an assertion error here, its probably access against
1531
1537
        # an unlocked repo. Naughty.
1532
1538
        if not self.repo.is_locked():
1538
1544
                name = key[0]
1539
1545
                self._names[name] = self._parse_index_sizes(value)
1540
1546
                self._packs_at_load.add((key, value))
 
1547
            result = True
 
1548
        else:
 
1549
            result = False
1541
1550
        # populate all the metadata.
1542
1551
        self.all_packs()
 
1552
        return result
1543
1553
 
1544
1554
    def _parse_index_sizes(self, value):
1545
1555
        """Parse a string of index sizes."""
1838
1848
        This should be called when we find out that something we thought was
1839
1849
        present is now missing. This happens when another process re-packs the
1840
1850
        repository, etc.
 
1851
 
 
1852
        :return: True if the in-memory list of packs has been altered at all.
1841
1853
        """
1842
 
        # This is functionally similar to _save_pack_names, but we don't write
 
1854
        # The ensure_loaded call is to handle the case where the first call
 
1855
        # made involving the collection was to reload_pack_names, where we 
 
1856
        # don't have a view of disk contents. Its a bit of a bandaid, and
 
1857
        # causes two reads of pack-names, but its a rare corner case not struck
 
1858
        # with regular push/pull etc.
 
1859
        first_read = self.ensure_loaded()
 
1860
        if first_read:
 
1861
            return True
1843
1862
        # out the new value.
1844
1863
        disk_nodes, _, _ = self._diff_pack_names()
1845
1864
        self._packs_at_load = disk_nodes
2085
2104
                pos, length = value[1:].split(' ')
2086
2105
                index_positions.append((index, int(pos), key[0],
2087
2106
                    tuple(parent[0] for parent in refs[0])))
2088
 
                pb.update("Reading revision index.", 0, 0)
 
2107
                pb.update("Reading revision index", 0, 0)
2089
2108
            index_positions.sort()
2090
2109
            batch_count = len(index_positions) / 1000 + 1
2091
 
            pb.update("Checking cached revision graph.", 0, batch_count)
 
2110
            pb.update("Checking cached revision graph", 0, batch_count)
2092
2111
            for offset in xrange(batch_count):
2093
 
                pb.update("Checking cached revision graph.", offset)
 
2112
                pb.update("Checking cached revision graph", offset)
2094
2113
                to_query = index_positions[offset * 1000:(offset + 1) * 1000]
2095
2114
                if not to_query:
2096
2115
                    break
2115
2134
        return graph.CachingParentsProvider(self)
2116
2135
 
2117
2136
    def _refresh_data(self):
2118
 
        if self._write_lock_count == 1 or (
2119
 
            self.control_files._lock_count == 1 and
2120
 
            self.control_files._lock_mode == 'r'):
2121
 
            # forget what names there are
2122
 
            self._pack_collection.reset()
2123
 
            # XXX: Better to do an in-memory merge when acquiring a new lock -
2124
 
            # factor out code from _save_pack_names.
2125
 
            self._pack_collection.ensure_loaded()
 
2137
        if not self.is_locked():
 
2138
            return
 
2139
        self._pack_collection.reload_pack_names()
2126
2140
 
2127
2141
    def _start_write_group(self):
2128
2142
        self._pack_collection._start_write_group()
2153
2167
        return self._write_lock_count
2154
2168
 
2155
2169
    def lock_write(self, token=None):
2156
 
        if not self._write_lock_count and self.is_locked():
 
2170
        locked = self.is_locked()
 
2171
        if not self._write_lock_count and locked:
2157
2172
            raise errors.ReadOnlyError(self)
2158
2173
        self._write_lock_count += 1
2159
2174
        if self._write_lock_count == 1:
2161
2176
            for repo in self._fallback_repositories:
2162
2177
                # Writes don't affect fallback repos
2163
2178
                repo.lock_read()
2164
 
        self._refresh_data()
 
2179
        if not locked:
 
2180
            self._refresh_data()
2165
2181
 
2166
2182
    def lock_read(self):
 
2183
        locked = self.is_locked()
2167
2184
        if self._write_lock_count:
2168
2185
            self._write_lock_count += 1
2169
2186
        else:
2171
2188
            for repo in self._fallback_repositories:
2172
2189
                # Writes don't affect fallback repos
2173
2190
                repo.lock_read()
2174
 
        self._refresh_data()
 
2191
        if not locked:
 
2192
            self._refresh_data()
2175
2193
 
2176
2194
    def leave_lock_in_place(self):
2177
2195
        # not supported - raise an error
2245
2263
    # Set this attribute in derived clases to control the _serializer that the
2246
2264
    # repository objects will have passed to their constructor.
2247
2265
    _serializer = None
 
2266
    # Packs are not confused by ghosts.
 
2267
    supports_ghosts = True
2248
2268
    # External references are not supported in pack repositories yet.
2249
2269
    supports_external_lookups = False
2250
2270
    # What index classes to use