/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

  • Committer: Parth Malwankar
  • Date: 2010-03-11 06:24:00 UTC
  • mto: (5094.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5107.
  • Revision ID: parth.malwankar@gmail.com-20100311062400-17bx45mt09fuhkri
closed Martins review comments.
from https://code.edge.launchpad.net/~parthm/bzr/376388-dot-bazaar-ownership/+merge/19691

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    GraphIndex,
65
65
    InMemoryGraphIndex,
66
66
    )
67
 
from bzrlib.lock import LogicalLockResult
68
67
from bzrlib.repofmt.knitrepo import KnitRepository
69
68
from bzrlib.repository import (
70
69
    CommitBuilder,
71
70
    MetaDirRepositoryFormat,
72
71
    RepositoryFormat,
73
 
    RepositoryWriteLockResult,
74
72
    RootCommitBuilder,
75
73
    StreamSource,
76
74
    )
589
587
                                             flush_func=flush_func)
590
588
        self.add_callback = None
591
589
 
 
590
    def replace_indices(self, index_to_pack, indices):
 
591
        """Replace the current mappings with fresh ones.
 
592
 
 
593
        This should probably not be used eventually, rather incremental add and
 
594
        removal of indices. It has been added during refactoring of existing
 
595
        code.
 
596
 
 
597
        :param index_to_pack: A mapping from index objects to
 
598
            (transport, name) tuples for the pack file data.
 
599
        :param indices: A list of indices.
 
600
        """
 
601
        # refresh the revision pack map dict without replacing the instance.
 
602
        self.index_to_pack.clear()
 
603
        self.index_to_pack.update(index_to_pack)
 
604
        # XXX: API break - clearly a 'replace' method would be good?
 
605
        self.combined_index._indices[:] = indices
 
606
        # the current add nodes callback for the current writable index if
 
607
        # there is one.
 
608
        self.add_callback = None
 
609
 
592
610
    def add_index(self, index, pack):
593
611
        """Add index to the aggregate, which is an index for Pack pack.
594
612
 
601
619
        # expose it to the index map
602
620
        self.index_to_pack[index] = pack.access_tuple()
603
621
        # put it at the front of the linear index list
604
 
        self.combined_index.insert_index(0, index, pack.name)
 
622
        self.combined_index.insert_index(0, index)
605
623
 
606
624
    def add_writable_index(self, index, pack):
607
625
        """Add an index which is able to have data added to it.
627
645
        self.data_access.set_writer(None, None, (None, None))
628
646
        self.index_to_pack.clear()
629
647
        del self.combined_index._indices[:]
630
 
        del self.combined_index._index_names[:]
631
648
        self.add_callback = None
632
649
 
633
650
    def remove_index(self, index):
636
653
        :param index: An index from the pack parameter.
637
654
        """
638
655
        del self.index_to_pack[index]
639
 
        pos = self.combined_index._indices.index(index)
640
 
        del self.combined_index._indices[pos]
641
 
        del self.combined_index._index_names[pos]
 
656
        self.combined_index._indices.remove(index)
642
657
        if (self.add_callback is not None and
643
658
            getattr(index, 'add_nodes', None) == self.add_callback):
644
659
            self.add_callback = None
1400
1415
        self.inventory_index = AggregateIndex(self.reload_pack_names, flush)
1401
1416
        self.text_index = AggregateIndex(self.reload_pack_names, flush)
1402
1417
        self.signature_index = AggregateIndex(self.reload_pack_names, flush)
1403
 
        all_indices = [self.revision_index, self.inventory_index,
1404
 
                self.text_index, self.signature_index]
1405
1418
        if use_chk_index:
1406
1419
            self.chk_index = AggregateIndex(self.reload_pack_names, flush)
1407
 
            all_indices.append(self.chk_index)
1408
1420
        else:
1409
1421
            # used to determine if we're using a chk_index elsewhere.
1410
1422
            self.chk_index = None
1411
 
        # Tell all the CombinedGraphIndex objects about each other, so they can
1412
 
        # share hints about which pack names to search first.
1413
 
        all_combined = [agg_idx.combined_index for agg_idx in all_indices]
1414
 
        for combined_idx in all_combined:
1415
 
            combined_idx.set_sibling_indices(
1416
 
                set(all_combined).difference([combined_idx]))
1417
1423
        # resumed packs
1418
1424
        self._resumed_packs = []
1419
1425
 
1562
1568
        """Is the collection already packed?"""
1563
1569
        return not (self.repo._format.pack_compresses or (len(self._names) > 1))
1564
1570
 
1565
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
1571
    def pack(self, hint=None):
1566
1572
        """Pack the pack collection totally."""
1567
1573
        self.ensure_loaded()
1568
1574
        total_packs = len(self._names)
1584
1590
                pack_operations[-1][1].append(pack)
1585
1591
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1586
1592
 
1587
 
        if clean_obsolete_packs:
1588
 
            self._clear_obsolete_packs()
1589
 
 
1590
1593
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1591
1594
        """Plan a pack operation.
1592
1595
 
2342
2345
        return self._write_lock_count
2343
2346
 
2344
2347
    def lock_write(self, token=None):
2345
 
        """Lock the repository for writes.
2346
 
 
2347
 
        :return: A bzrlib.repository.RepositoryWriteLockResult.
2348
 
        """
2349
2348
        locked = self.is_locked()
2350
2349
        if not self._write_lock_count and locked:
2351
2350
            raise errors.ReadOnlyError(self)
2360
2359
                # Writes don't affect fallback repos
2361
2360
                repo.lock_read()
2362
2361
            self._refresh_data()
2363
 
        return RepositoryWriteLockResult(self.unlock, None)
2364
2362
 
2365
2363
    def lock_read(self):
2366
 
        """Lock the repository for reads.
2367
 
 
2368
 
        :return: A bzrlib.lock.LogicalLockResult.
2369
 
        """
2370
2364
        locked = self.is_locked()
2371
2365
        if self._write_lock_count:
2372
2366
            self._write_lock_count += 1
2379
2373
            for repo in self._fallback_repositories:
2380
2374
                repo.lock_read()
2381
2375
            self._refresh_data()
2382
 
        return LogicalLockResult(self.unlock)
2383
2376
 
2384
2377
    def leave_lock_in_place(self):
2385
2378
        # not supported - raise an error
2390
2383
        raise NotImplementedError(self.dont_leave_lock_in_place)
2391
2384
 
2392
2385
    @needs_write_lock
2393
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
2386
    def pack(self, hint=None):
2394
2387
        """Compress the data within the repository.
2395
2388
 
2396
2389
        This will pack all the data to a single pack. In future it may
2397
2390
        recompress deltas or do other such expensive operations.
2398
2391
        """
2399
 
        self._pack_collection.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
 
2392
        self._pack_collection.pack(hint=hint)
2400
2393
 
2401
2394
    @needs_write_lock
2402
2395
    def reconcile(self, other=None, thorough=False):
2558
2551
        utf8_files = [('format', self.get_format_string())]
2559
2552
 
2560
2553
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
2561
 
        repository = self.open(a_bzrdir=a_bzrdir, _found=True)
2562
 
        self._run_post_repo_init_hooks(repository, a_bzrdir, shared)
2563
 
        return repository
 
2554
        return self.open(a_bzrdir=a_bzrdir, _found=True)
2564
2555
 
2565
2556
    def open(self, a_bzrdir, _found=False, _override_transport=None):
2566
2557
        """See RepositoryFormat.open().