~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Robert Collins
  • Date: 2009-03-16 05:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 4149.
  • Revision ID: robertc@robertcollins.net-20090316050552-hqcgx49ugew0facc
Add a refresh_data method on Repository allowing cleaner handling of insertions into RemoteRepository objects with _real_repository instances.

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
1839
1841
        present is now missing. This happens when another process re-packs the
1840
1842
        repository, etc.
1841
1843
        """
 
1844
        # The ensure_loaded call is to handle the case where the first call
 
1845
        # made involving the collection was to reload_pack_names, where we 
 
1846
        # don't have a view of disk contents. Its a bit of a bandaid, and
 
1847
        # causes two reads of pack-names, but its a rare corner case not struck
 
1848
        # with regular push/pull etc.
 
1849
        self.ensure_loaded()
1842
1850
        # This is functionally similar to _save_pack_names, but we don't write
1843
1851
        # out the new value.
1844
1852
        disk_nodes, _, _ = self._diff_pack_names()
2115
2123
        return graph.CachingParentsProvider(self)
2116
2124
 
2117
2125
    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()
 
2126
        if not self.is_locked():
 
2127
            return
 
2128
        self._pack_collection.reload_pack_names()
2126
2129
 
2127
2130
    def _start_write_group(self):
2128
2131
        self._pack_collection._start_write_group()
2153
2156
        return self._write_lock_count
2154
2157
 
2155
2158
    def lock_write(self, token=None):
2156
 
        if not self._write_lock_count and self.is_locked():
 
2159
        locked = self.is_locked()
 
2160
        if not self._write_lock_count and locked:
2157
2161
            raise errors.ReadOnlyError(self)
2158
2162
        self._write_lock_count += 1
2159
2163
        if self._write_lock_count == 1:
2161
2165
            for repo in self._fallback_repositories:
2162
2166
                # Writes don't affect fallback repos
2163
2167
                repo.lock_read()
2164
 
        self._refresh_data()
 
2168
        if not locked:
 
2169
            self._refresh_data()
2165
2170
 
2166
2171
    def lock_read(self):
 
2172
        locked = self.is_locked()
2167
2173
        if self._write_lock_count:
2168
2174
            self._write_lock_count += 1
2169
2175
        else:
2171
2177
            for repo in self._fallback_repositories:
2172
2178
                # Writes don't affect fallback repos
2173
2179
                repo.lock_read()
2174
 
        self._refresh_data()
 
2180
        if not locked:
 
2181
            self._refresh_data()
2175
2182
 
2176
2183
    def leave_lock_in_place(self):
2177
2184
        # not supported - raise an error