~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-17 17:16:09 UTC
  • mfrom: (6272 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6273.
  • Revision ID: v.ladeuil+lp@free.fr-20111117171609-pzs107pdm0vndlf9
merge trunk to resolve conflicts on news

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    SmartProtocolError,
42
42
    )
43
43
from bzrlib.i18n import gettext
 
44
from bzrlib.inventory import Inventory
44
45
from bzrlib.lockable_files import LockableFiles
45
46
from bzrlib.smart import client, vfs, repository as smart_repo
46
47
from bzrlib.smart.client import _SmartClient
47
48
from bzrlib.revision import NULL_REVISION
 
49
from bzrlib.revisiontree import InventoryRevisionTree
48
50
from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
49
51
from bzrlib.trace import mutter, note, warning
50
52
 
698
700
        """Upgrading of remote bzrdirs is not supported yet."""
699
701
        return False
700
702
 
701
 
    def clone(self, url, revision_id=None, force_new_repo=False,
702
 
              preserve_stacking=False):
703
 
        self._ensure_real()
704
 
        return self._real_bzrdir.clone(url, revision_id=revision_id,
705
 
            force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
706
 
 
707
703
    def _get_config(self):
708
704
        return RemoteBzrDirConfig(self)
709
705
 
1479
1475
            return t
1480
1476
        raise errors.UnexpectedSmartServerResponse(response)
1481
1477
 
 
1478
    @needs_read_lock
1482
1479
    def sprout(self, to_bzrdir, revision_id=None):
1483
 
        # TODO: Option to control what format is created?
1484
 
        self._ensure_real()
1485
 
        dest_repo = self._real_repository._format.initialize(to_bzrdir,
1486
 
                                                             shared=False)
 
1480
        """Create a descendent repository for new development.
 
1481
 
 
1482
        Unlike clone, this does not copy the settings of the repository.
 
1483
        """
 
1484
        dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1487
1485
        dest_repo.fetch(self, revision_id=revision_id)
1488
1486
        return dest_repo
1489
1487
 
 
1488
    def _create_sprouting_repo(self, a_bzrdir, shared):
 
1489
        if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
 
1490
            # use target default format.
 
1491
            dest_repo = a_bzrdir.create_repository()
 
1492
        else:
 
1493
            # Most control formats need the repository to be specifically
 
1494
            # created, but on some old all-in-one formats it's not needed
 
1495
            try:
 
1496
                dest_repo = self._format.initialize(a_bzrdir, shared=shared)
 
1497
            except errors.UninitializableFormat:
 
1498
                dest_repo = a_bzrdir.open_repository()
 
1499
        return dest_repo
 
1500
 
1490
1501
    ### These methods are just thin shims to the VFS object for now.
1491
1502
 
 
1503
    @needs_read_lock
1492
1504
    def revision_tree(self, revision_id):
1493
 
        self._ensure_real()
1494
 
        return self._real_repository.revision_tree(revision_id)
 
1505
        revision_id = _mod_revision.ensure_null(revision_id)
 
1506
        if revision_id == _mod_revision.NULL_REVISION:
 
1507
            return InventoryRevisionTree(self,
 
1508
                Inventory(root_id=None), _mod_revision.NULL_REVISION)
 
1509
        else:
 
1510
            return list(self.revision_trees([revision_id]))[0]
1495
1511
 
1496
1512
    def get_serializer_format(self):
1497
1513
        self._ensure_real()
1575
1591
 
1576
1592
    @needs_read_lock
1577
1593
    def get_revision(self, revision_id):
1578
 
        self._ensure_real()
1579
 
        return self._real_repository.get_revision(revision_id)
 
1594
        return self.get_revisions([revision_id])[0]
1580
1595
 
1581
1596
    def get_transaction(self):
1582
1597
        self._ensure_real()
1584
1599
 
1585
1600
    @needs_read_lock
1586
1601
    def clone(self, a_bzrdir, revision_id=None):
1587
 
        self._ensure_real()
1588
 
        return self._real_repository.clone(a_bzrdir, revision_id=revision_id)
 
1602
        dest_repo = self._create_sprouting_repo(
 
1603
            a_bzrdir, shared=self.is_shared())
 
1604
        self.copy_content_into(dest_repo, revision_id)
 
1605
        return dest_repo
1589
1606
 
1590
1607
    def make_working_trees(self):
1591
1608
        """See Repository.make_working_trees"""
1592
 
        self._ensure_real()
1593
 
        return self._real_repository.make_working_trees()
 
1609
        path = self.bzrdir._path_for_remote_call(self._client)
 
1610
        try:
 
1611
            response = self._call('Repository.make_working_trees', path)
 
1612
        except errors.UnknownSmartMethod:
 
1613
            self._ensure_real()
 
1614
            return self._real_repository.make_working_trees()
 
1615
        if response[0] not in ('yes', 'no'):
 
1616
            raise SmartProtocolError('unexpected response code %s' % (response,))
 
1617
        return response[0] == 'yes'
1594
1618
 
1595
1619
    def refresh_data(self):
1596
1620
        """Re-read any data needed to synchronise with disk.
1852
1876
 
1853
1877
    @needs_read_lock
1854
1878
    def get_revision_delta(self, revision_id, specific_fileids=None):
1855
 
        self._ensure_real()
1856
 
        return self._real_repository.get_revision_delta(revision_id,
1857
 
            specific_fileids=specific_fileids)
 
1879
        r = self.get_revision(revision_id)
 
1880
        return list(self.get_deltas_for_revisions([r],
 
1881
            specific_fileids=specific_fileids))[0]
1858
1882
 
1859
1883
    @needs_read_lock
1860
1884
    def revision_trees(self, revision_ids):
1873
1897
            callback_refs=callback_refs, check_repo=check_repo)
1874
1898
 
1875
1899
    def copy_content_into(self, destination, revision_id=None):
1876
 
        self._ensure_real()
1877
 
        return self._real_repository.copy_content_into(
1878
 
            destination, revision_id=revision_id)
 
1900
        """Make a complete copy of the content in self into destination.
 
1901
 
 
1902
        This is a destructive operation! Do not use it on existing
 
1903
        repositories.
 
1904
        """
 
1905
        interrepo = _mod_repository.InterRepository.get(self, destination)
 
1906
        return interrepo.copy_content(revision_id)
1879
1907
 
1880
1908
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
1881
1909
        # get a tarball of the remote repository, and copy from that into the
1994
2022
    def _serializer(self):
1995
2023
        return self._format._serializer
1996
2024
 
 
2025
    @needs_write_lock
1997
2026
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1998
 
        self._ensure_real()
1999
 
        return self._real_repository.store_revision_signature(
2000
 
            gpg_strategy, plaintext, revision_id)
 
2027
        signature = gpg_strategy.sign(plaintext)
 
2028
        self.add_signature_text(revision_id, signature)
2001
2029
 
2002
2030
    def add_signature_text(self, revision_id, signature):
2003
2031
        self._ensure_real()
2004
2032
        return self._real_repository.add_signature_text(revision_id, signature)
2005
2033
 
2006
2034
    def has_signature_for_revision_id(self, revision_id):
 
2035
        path = self.bzrdir._path_for_remote_call(self._client)
 
2036
        try:
 
2037
            response = self._call('Repository.has_signature_for_revision_id',
 
2038
                path, revision_id)
 
2039
        except errors.UnknownSmartMethod:
 
2040
            self._ensure_real()
 
2041
            return self._real_repository.has_signature_for_revision_id(
 
2042
                revision_id)
 
2043
        if response[0] not in ('yes', 'no'):
 
2044
            raise SmartProtocolError('unexpected response code %s' % (response,))
 
2045
        return (response[0] == 'yes')
 
2046
 
 
2047
    def verify_revision_signature(self, revision_id, gpg_strategy):
2007
2048
        self._ensure_real()
2008
 
        return self._real_repository.has_signature_for_revision_id(revision_id)
 
2049
        return self._real_repository.verify_revision_signature(
 
2050
            revision_id, gpg_strategy)
2009
2051
 
2010
2052
    def item_keys_introduced_by(self, revision_ids, _files_pb=None):
2011
2053
        self._ensure_real()