~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-15 18:09:55 UTC
  • mfrom: (5159.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100415180955-v9jh960r07pva92c
(vila) Merge 2.1 into bzr.dev including fixes for #262450, #373898,
        #498409

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
""")
50
50
from bzrlib import (
51
51
    bzrdir,
52
 
    btree_index,
53
52
    errors,
54
53
    lockable_files,
55
54
    lockdir,
57
56
    )
58
57
 
59
58
from bzrlib.decorators import needs_write_lock, only_raises
 
59
from bzrlib.btree_index import (
 
60
    BTreeGraphIndex,
 
61
    BTreeBuilder,
 
62
    )
60
63
from bzrlib.index import (
61
64
    GraphIndex,
62
65
    InMemoryGraphIndex,
63
66
    )
64
 
from bzrlib.lock import LogicalLockResult
65
67
from bzrlib.repofmt.knitrepo import KnitRepository
66
68
from bzrlib.repository import (
67
69
    CommitBuilder,
68
70
    MetaDirRepositoryFormat,
69
71
    RepositoryFormat,
70
 
    RepositoryWriteLockResult,
71
72
    RootCommitBuilder,
72
73
    StreamSource,
73
74
    )
228
229
        unlimited_cache = False
229
230
        if index_type == 'chk':
230
231
            unlimited_cache = True
231
 
        index = self.index_class(self.index_transport,
232
 
                    self.index_name(index_type, self.name),
233
 
                    self.index_sizes[self.index_offset(index_type)],
234
 
                    unlimited_cache=unlimited_cache)
235
 
        if index_type == 'chk':
236
 
            index._leaf_factory = btree_index._gcchk_factory
237
 
        setattr(self, index_type + '_index', index)
 
232
        setattr(self, index_type + '_index',
 
233
            self.index_class(self.index_transport,
 
234
                self.index_name(index_type, self.name),
 
235
                self.index_sizes[self.index_offset(index_type)],
 
236
                unlimited_cache=unlimited_cache))
238
237
 
239
238
 
240
239
class ExistingPack(Pack):
1561
1560
        """Is the collection already packed?"""
1562
1561
        return not (self.repo._format.pack_compresses or (len(self._names) > 1))
1563
1562
 
1564
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
1563
    def pack(self, hint=None):
1565
1564
        """Pack the pack collection totally."""
1566
1565
        self.ensure_loaded()
1567
1566
        total_packs = len(self._names)
1583
1582
                pack_operations[-1][1].append(pack)
1584
1583
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1585
1584
 
1586
 
        if clean_obsolete_packs:
1587
 
            self._clear_obsolete_packs()
1588
 
 
1589
1585
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1590
1586
        """Plan a pack operation.
1591
1587
 
1679
1675
            txt_index = self._make_index(name, '.tix')
1680
1676
            sig_index = self._make_index(name, '.six')
1681
1677
            if self.chk_index is not None:
1682
 
                chk_index = self._make_index(name, '.cix', is_chk=True)
 
1678
                chk_index = self._make_index(name, '.cix', unlimited_cache=True)
1683
1679
            else:
1684
1680
                chk_index = None
1685
1681
            result = ExistingPack(self._pack_transport, name, rev_index,
1705
1701
            sig_index = self._make_index(name, '.six', resume=True)
1706
1702
            if self.chk_index is not None:
1707
1703
                chk_index = self._make_index(name, '.cix', resume=True,
1708
 
                                             is_chk=True)
 
1704
                                             unlimited_cache=True)
1709
1705
            else:
1710
1706
                chk_index = None
1711
1707
            result = self.resumed_pack_factory(name, rev_index, inv_index,
1741
1737
        return self._index_class(self.transport, 'pack-names', None
1742
1738
                ).iter_all_entries()
1743
1739
 
1744
 
    def _make_index(self, name, suffix, resume=False, is_chk=False):
 
1740
    def _make_index(self, name, suffix, resume=False, unlimited_cache=False):
1745
1741
        size_offset = self._suffix_offsets[suffix]
1746
1742
        index_name = name + suffix
1747
1743
        if resume:
1750
1746
        else:
1751
1747
            transport = self._index_transport
1752
1748
            index_size = self._names[name][size_offset]
1753
 
        index = self._index_class(transport, index_name, index_size,
1754
 
                                  unlimited_cache=is_chk)
1755
 
        if is_chk and self._index_class is btree_index.BTreeGraphIndex: 
1756
 
            index._leaf_factory = btree_index._gcchk_factory
1757
 
        return index
 
1749
        return self._index_class(transport, index_name, index_size,
 
1750
                                 unlimited_cache=unlimited_cache)
1758
1751
 
1759
1752
    def _max_pack_count(self, total_revisions):
1760
1753
        """Return the maximum number of packs to use for total revisions.
2344
2337
        return self._write_lock_count
2345
2338
 
2346
2339
    def lock_write(self, token=None):
2347
 
        """Lock the repository for writes.
2348
 
 
2349
 
        :return: A bzrlib.repository.RepositoryWriteLockResult.
2350
 
        """
2351
2340
        locked = self.is_locked()
2352
2341
        if not self._write_lock_count and locked:
2353
2342
            raise errors.ReadOnlyError(self)
2362
2351
                # Writes don't affect fallback repos
2363
2352
                repo.lock_read()
2364
2353
            self._refresh_data()
2365
 
        return RepositoryWriteLockResult(self.unlock, None)
2366
2354
 
2367
2355
    def lock_read(self):
2368
 
        """Lock the repository for reads.
2369
 
 
2370
 
        :return: A bzrlib.lock.LogicalLockResult.
2371
 
        """
2372
2356
        locked = self.is_locked()
2373
2357
        if self._write_lock_count:
2374
2358
            self._write_lock_count += 1
2381
2365
            for repo in self._fallback_repositories:
2382
2366
                repo.lock_read()
2383
2367
            self._refresh_data()
2384
 
        return LogicalLockResult(self.unlock)
2385
2368
 
2386
2369
    def leave_lock_in_place(self):
2387
2370
        # not supported - raise an error
2392
2375
        raise NotImplementedError(self.dont_leave_lock_in_place)
2393
2376
 
2394
2377
    @needs_write_lock
2395
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
2378
    def pack(self, hint=None):
2396
2379
        """Compress the data within the repository.
2397
2380
 
2398
2381
        This will pack all the data to a single pack. In future it may
2399
2382
        recompress deltas or do other such expensive operations.
2400
2383
        """
2401
 
        self._pack_collection.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
 
2384
        self._pack_collection.pack(hint=hint)
2402
2385
 
2403
2386
    @needs_write_lock
2404
2387
    def reconcile(self, other=None, thorough=False):
2560
2543
        utf8_files = [('format', self.get_format_string())]
2561
2544
 
2562
2545
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
2563
 
        repository = self.open(a_bzrdir=a_bzrdir, _found=True)
2564
 
        self._run_post_repo_init_hooks(repository, a_bzrdir, shared)
2565
 
        return repository
 
2546
        return self.open(a_bzrdir=a_bzrdir, _found=True)
2566
2547
 
2567
2548
    def open(self, a_bzrdir, _found=False, _override_transport=None):
2568
2549
        """See RepositoryFormat.open().
2831
2812
    _commit_builder_class = PackCommitBuilder
2832
2813
    supports_external_lookups = True
2833
2814
    # What index classes to use
2834
 
    index_builder_class = btree_index.BTreeBuilder
2835
 
    index_class = btree_index.BTreeGraphIndex
 
2815
    index_builder_class = BTreeBuilder
 
2816
    index_class = BTreeGraphIndex
2836
2817
 
2837
2818
    @property
2838
2819
    def _serializer(self):
2867
2848
    supports_tree_reference = False # no subtrees
2868
2849
    supports_external_lookups = True
2869
2850
    # What index classes to use
2870
 
    index_builder_class = btree_index.BTreeBuilder
2871
 
    index_class = btree_index.BTreeGraphIndex
 
2851
    index_builder_class = BTreeBuilder
 
2852
    index_class = BTreeGraphIndex
2872
2853
 
2873
2854
    @property
2874
2855
    def _serializer(self):
2909
2890
    supports_tree_reference = True
2910
2891
    supports_external_lookups = True
2911
2892
    # What index classes to use
2912
 
    index_builder_class = btree_index.BTreeBuilder
2913
 
    index_class = btree_index.BTreeGraphIndex
 
2893
    index_builder_class = BTreeBuilder
 
2894
    index_class = BTreeGraphIndex
2914
2895
 
2915
2896
    @property
2916
2897
    def _serializer(self):