~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-05-20 09:27:48 UTC
  • mfrom: (5241.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20100520092748-oa7knubtqio8l2rc
(lifeless) Merge 2.1 into trunk with a number of fixes including pyrex 0.9.9
 support. (Robert Collins)

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
67
68
from bzrlib.repofmt.knitrepo import KnitRepository
68
69
from bzrlib.repository import (
69
70
    CommitBuilder,
70
71
    MetaDirRepositoryFormat,
71
72
    RepositoryFormat,
 
73
    RepositoryWriteLockResult,
72
74
    RootCommitBuilder,
73
75
    StreamSource,
74
76
    )
1560
1562
        """Is the collection already packed?"""
1561
1563
        return not (self.repo._format.pack_compresses or (len(self._names) > 1))
1562
1564
 
1563
 
    def pack(self, hint=None):
 
1565
    def pack(self, hint=None, clean_obsolete_packs=False):
1564
1566
        """Pack the pack collection totally."""
1565
1567
        self.ensure_loaded()
1566
1568
        total_packs = len(self._names)
1582
1584
                pack_operations[-1][1].append(pack)
1583
1585
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1584
1586
 
 
1587
        if clean_obsolete_packs:
 
1588
            self._clear_obsolete_packs()
 
1589
 
1585
1590
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1586
1591
        """Plan a pack operation.
1587
1592
 
2337
2342
        return self._write_lock_count
2338
2343
 
2339
2344
    def lock_write(self, token=None):
 
2345
        """Lock the repository for writes.
 
2346
 
 
2347
        :return: A bzrlib.repository.RepositoryWriteLockResult.
 
2348
        """
2340
2349
        locked = self.is_locked()
2341
2350
        if not self._write_lock_count and locked:
2342
2351
            raise errors.ReadOnlyError(self)
2351
2360
                # Writes don't affect fallback repos
2352
2361
                repo.lock_read()
2353
2362
            self._refresh_data()
 
2363
        return RepositoryWriteLockResult(self.unlock, None)
2354
2364
 
2355
2365
    def lock_read(self):
 
2366
        """Lock the repository for reads.
 
2367
 
 
2368
        :return: A bzrlib.lock.LogicalLockResult.
 
2369
        """
2356
2370
        locked = self.is_locked()
2357
2371
        if self._write_lock_count:
2358
2372
            self._write_lock_count += 1
2365
2379
            for repo in self._fallback_repositories:
2366
2380
                repo.lock_read()
2367
2381
            self._refresh_data()
 
2382
        return LogicalLockResult(self.unlock)
2368
2383
 
2369
2384
    def leave_lock_in_place(self):
2370
2385
        # not supported - raise an error
2375
2390
        raise NotImplementedError(self.dont_leave_lock_in_place)
2376
2391
 
2377
2392
    @needs_write_lock
2378
 
    def pack(self, hint=None):
 
2393
    def pack(self, hint=None, clean_obsolete_packs=False):
2379
2394
        """Compress the data within the repository.
2380
2395
 
2381
2396
        This will pack all the data to a single pack. In future it may
2382
2397
        recompress deltas or do other such expensive operations.
2383
2398
        """
2384
 
        self._pack_collection.pack(hint=hint)
 
2399
        self._pack_collection.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
2385
2400
 
2386
2401
    @needs_write_lock
2387
2402
    def reconcile(self, other=None, thorough=False):
2543
2558
        utf8_files = [('format', self.get_format_string())]
2544
2559
 
2545
2560
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
2546
 
        return self.open(a_bzrdir=a_bzrdir, _found=True)
 
2561
        repository = self.open(a_bzrdir=a_bzrdir, _found=True)
 
2562
        self._run_post_repo_init_hooks(repository, a_bzrdir, shared)
 
2563
        return repository
2547
2564
 
2548
2565
    def open(self, a_bzrdir, _found=False, _override_transport=None):
2549
2566
        """See RepositoryFormat.open().