/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Ā upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import re
18
18
import sys
532
532
    # XXX: Probably 'can be written to' could/should be separated from 'acts
533
533
    # like a knit index' -- mbp 20071024
534
534
 
535
 
    def __init__(self, reload_func=None):
 
535
    def __init__(self, reload_func=None, flush_func=None):
536
536
        """Create an AggregateIndex.
537
537
 
538
538
        :param reload_func: A function to call if we find we are missing an
543
543
        self.index_to_pack = {}
544
544
        self.combined_index = CombinedGraphIndex([], reload_func=reload_func)
545
545
        self.data_access = _DirectPackAccess(self.index_to_pack,
546
 
                                             reload_func=reload_func)
 
546
                                             reload_func=reload_func,
 
547
                                             flush_func=flush_func)
547
548
        self.add_callback = None
548
549
 
549
550
    def replace_indices(self, index_to_pack, indices):
725
726
 
726
727
    def open_pack(self):
727
728
        """Open a pack for the pack we are creating."""
728
 
        return NewPack(self._pack_collection, upload_suffix=self.suffix,
 
729
        new_pack = NewPack(self._pack_collection, upload_suffix=self.suffix,
729
730
                file_mode=self._pack_collection.repo.bzrdir._get_file_mode())
 
731
        # We know that we will process all nodes in order, and don't need to
 
732
        # query, so don't combine any indices spilled to disk until we are done
 
733
        new_pack.revision_index.set_optimize(combine_backing_indices=False)
 
734
        new_pack.inventory_index.set_optimize(combine_backing_indices=False)
 
735
        new_pack.text_index.set_optimize(combine_backing_indices=False)
 
736
        new_pack.signature_index.set_optimize(combine_backing_indices=False)
 
737
        return new_pack
730
738
 
731
739
    def _update_pack_order(self, entries, index_to_pack_map):
732
740
        """Determine how we want our packs to be ordered.
1297
1305
        :param index_builder_class: The index builder class to use.
1298
1306
        :param index_class: The index class to use.
1299
1307
        """
 
1308
        # XXX: This should call self.reset()
1300
1309
        self.repo = repo
1301
1310
        self.transport = transport
1302
1311
        self._index_transport = index_transport
1307
1316
        self._suffix_offsets = {'.rix': 0, '.iix': 1, '.tix': 2, '.six': 3}
1308
1317
        self.packs = []
1309
1318
        # name:Pack mapping
 
1319
        self._names = None
1310
1320
        self._packs_by_name = {}
1311
1321
        # the previous pack-names content
1312
1322
        self._packs_at_load = None
1313
1323
        # when a pack is being created by this object, the state of that pack.
1314
1324
        self._new_pack = None
1315
1325
        # aggregated revision index data
1316
 
        self.revision_index = AggregateIndex(self.reload_pack_names)
1317
 
        self.inventory_index = AggregateIndex(self.reload_pack_names)
1318
 
        self.text_index = AggregateIndex(self.reload_pack_names)
1319
 
        self.signature_index = AggregateIndex(self.reload_pack_names)
 
1326
        flush = self._flush_new_pack
 
1327
        self.revision_index = AggregateIndex(self.reload_pack_names, flush)
 
1328
        self.inventory_index = AggregateIndex(self.reload_pack_names, flush)
 
1329
        self.text_index = AggregateIndex(self.reload_pack_names, flush)
 
1330
        self.signature_index = AggregateIndex(self.reload_pack_names, flush)
1320
1331
        # resumed packs
1321
1332
        self._resumed_packs = []
1322
1333
 
1443
1454
        for revision_count, packs in pack_operations:
1444
1455
            self._obsolete_packs(packs)
1445
1456
 
 
1457
    def _flush_new_pack(self):
 
1458
        if self._new_pack is not None:
 
1459
            self._new_pack.flush()
 
1460
 
1446
1461
    def lock_names(self):
1447
1462
        """Acquire the mutex around the pack-names index.
1448
1463
 
1527
1542
        return [[final_rev_count, final_pack_list]]
1528
1543
 
1529
1544
    def ensure_loaded(self):
 
1545
        """Ensure we have read names from disk.
 
1546
 
 
1547
        :return: True if the disk names had not been previously read.
 
1548
        """
1530
1549
        # NB: if you see an assertion error here, its probably access against
1531
1550
        # an unlocked repo. Naughty.
1532
1551
        if not self.repo.is_locked():
1538
1557
                name = key[0]
1539
1558
                self._names[name] = self._parse_index_sizes(value)
1540
1559
                self._packs_at_load.add((key, value))
 
1560
            result = True
 
1561
        else:
 
1562
            result = False
1541
1563
        # populate all the metadata.
1542
1564
        self.all_packs()
 
1565
        return result
1543
1566
 
1544
1567
    def _parse_index_sizes(self, value):
1545
1568
        """Parse a string of index sizes."""
1838
1861
        This should be called when we find out that something we thought was
1839
1862
        present is now missing. This happens when another process re-packs the
1840
1863
        repository, etc.
 
1864
 
 
1865
        :return: True if the in-memory list of packs has been altered at all.
1841
1866
        """
1842
 
        # This is functionally similar to _save_pack_names, but we don't write
 
1867
        # The ensure_loaded call is to handle the case where the first call
 
1868
        # made involving the collection was to reload_pack_names, where we 
 
1869
        # don't have a view of disk contents. Its a bit of a bandaid, and
 
1870
        # causes two reads of pack-names, but its a rare corner case not struck
 
1871
        # with regular push/pull etc.
 
1872
        first_read = self.ensure_loaded()
 
1873
        if first_read:
 
1874
            return True
1843
1875
        # out the new value.
1844
1876
        disk_nodes, _, _ = self._diff_pack_names()
1845
1877
        self._packs_at_load = disk_nodes
2105
2137
            pb.finished()
2106
2138
        return result
2107
2139
 
2108
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
2109
 
    def get_parents(self, revision_ids):
2110
 
        """See graph._StackedParentsProvider.get_parents."""
2111
 
        parent_map = self.get_parent_map(revision_ids)
2112
 
        return [parent_map.get(r, None) for r in revision_ids]
2113
 
 
2114
2140
    def _make_parents_provider(self):
2115
2141
        return graph.CachingParentsProvider(self)
2116
2142
 
2117
2143
    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()
 
2144
        if not self.is_locked():
 
2145
            return
 
2146
        self._pack_collection.reload_pack_names()
2126
2147
 
2127
2148
    def _start_write_group(self):
2128
2149
        self._pack_collection._start_write_group()
2153
2174
        return self._write_lock_count
2154
2175
 
2155
2176
    def lock_write(self, token=None):
2156
 
        if not self._write_lock_count and self.is_locked():
 
2177
        locked = self.is_locked()
 
2178
        if not self._write_lock_count and locked:
2157
2179
            raise errors.ReadOnlyError(self)
2158
2180
        self._write_lock_count += 1
2159
2181
        if self._write_lock_count == 1:
2161
2183
            for repo in self._fallback_repositories:
2162
2184
                # Writes don't affect fallback repos
2163
2185
                repo.lock_read()
2164
 
        self._refresh_data()
 
2186
        if not locked:
 
2187
            self._refresh_data()
2165
2188
 
2166
2189
    def lock_read(self):
 
2190
        locked = self.is_locked()
2167
2191
        if self._write_lock_count:
2168
2192
            self._write_lock_count += 1
2169
2193
        else:
2171
2195
            for repo in self._fallback_repositories:
2172
2196
                # Writes don't affect fallback repos
2173
2197
                repo.lock_read()
2174
 
        self._refresh_data()
 
2198
        if not locked:
 
2199
            self._refresh_data()
2175
2200
 
2176
2201
    def leave_lock_in_place(self):
2177
2202
        # not supported - raise an error
2253
2278
    index_builder_class = None
2254
2279
    index_class = None
2255
2280
    _fetch_uses_deltas = True
 
2281
    fast_deltas = False
2256
2282
 
2257
2283
    def initialize(self, a_bzrdir, shared=False):
2258
2284
        """Create a pack based repository.
2648
2674
    # What index classes to use
2649
2675
    index_builder_class = BTreeBuilder
2650
2676
    index_class = BTreeGraphIndex
 
2677
    # Set to true to get the fast-commit code path tested until a really fast
 
2678
    # format lands in trunk. Not actually fast in this format.
 
2679
    fast_deltas = True
2651
2680
 
2652
2681
    @property
2653
2682
    def _serializer(self):