~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:44:12 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105104412-z03fi9m43h946fvs
Merge bzr.dev to resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import bz2
18
20
import zlib
19
21
 
21
23
    bencode,
22
24
    branch,
23
25
    bzrdir as _mod_bzrdir,
24
 
    config,
 
26
    config as _mod_config,
25
27
    controldir,
26
28
    debug,
27
29
    errors,
57
59
from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
58
60
from bzrlib.serializer import format_registry as serializer_format_registry
59
61
from bzrlib.trace import mutter, note, warning, log_exception_quietly
 
62
from bzrlib.versionedfile import ChunkedContentFactory, FulltextContentFactory
60
63
 
61
64
 
62
65
_DEFAULT_SEARCH_DEPTH = 100
346
349
        _mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
347
350
 
348
351
 
349
 
class RemoteControlStore(config.IniFileStore):
 
352
class RemoteControlStore(_mod_config.IniFileStore):
350
353
    """Control store which attempts to use HPSS calls to retrieve control store.
351
354
 
352
355
    Note that this is specific to bzr-based formats.
376
379
    def _ensure_real(self):
377
380
        self.bzrdir._ensure_real()
378
381
        if self._real_store is None:
379
 
            self._real_store = config.ControlStore(self.bzrdir)
 
382
            self._real_store = _mod_config.ControlStore(self.bzrdir)
380
383
 
381
384
    def external_url(self):
382
385
        return self.bzrdir.user_url
478
481
                warning('VFS BzrDir access triggered\n%s',
479
482
                    ''.join(traceback.format_stack()))
480
483
            self._real_bzrdir = _mod_bzrdir.BzrDir.open_from_transport(
481
 
                self.root_transport, _server_formats=False)
 
484
                self.root_transport, probers=[_mod_bzrdir.BzrProber])
482
485
            self._format._network_name = \
483
486
                self._real_bzrdir._format.network_name()
484
487
 
1209
1212
        if response != ('ok', ):
1210
1213
            raise errors.UnexpectedSmartServerResponse(response)
1211
1214
        self._write_group_tokens = None
 
1215
        # Refresh data after writing to the repository.
 
1216
        self.refresh_data()
1212
1217
 
1213
1218
    def resume_write_group(self, tokens):
1214
1219
        if self._real_repository:
1763
1768
    def get_commit_builder(self, branch, parents, config, timestamp=None,
1764
1769
                           timezone=None, committer=None, revprops=None,
1765
1770
                           revision_id=None, lossy=False):
1766
 
        # FIXME: It ought to be possible to call this without immediately
1767
 
        # triggering _ensure_real.  For now it's the easiest thing to do.
1768
 
        self._ensure_real()
1769
 
        real_repo = self._real_repository
1770
 
        builder = real_repo.get_commit_builder(branch, parents,
1771
 
                config, timestamp=timestamp, timezone=timezone,
1772
 
                committer=committer, revprops=revprops,
1773
 
                revision_id=revision_id, lossy=lossy)
1774
 
        return builder
 
1771
        """Obtain a CommitBuilder for this repository.
 
1772
 
 
1773
        :param branch: Branch to commit to.
 
1774
        :param parents: Revision ids of the parents of the new revision.
 
1775
        :param config: Configuration to use.
 
1776
        :param timestamp: Optional timestamp recorded for commit.
 
1777
        :param timezone: Optional timezone for timestamp.
 
1778
        :param committer: Optional committer to set for commit.
 
1779
        :param revprops: Optional dictionary of revision properties.
 
1780
        :param revision_id: Optional revision id.
 
1781
        :param lossy: Whether to discard data that can not be natively
 
1782
            represented, when pushing to a foreign VCS
 
1783
        """
 
1784
        if self._fallback_repositories and not self._format.supports_chks:
 
1785
            raise errors.BzrError("Cannot commit directly to a stacked branch"
 
1786
                " in pre-2a formats. See "
 
1787
                "https://bugs.launchpad.net/bzr/+bug/375013 for details.")
 
1788
        if self._format.rich_root_data:
 
1789
            commit_builder_kls = vf_repository.VersionedFileRootCommitBuilder
 
1790
        else:
 
1791
            commit_builder_kls = vf_repository.VersionedFileCommitBuilder
 
1792
        result = commit_builder_kls(self, parents, config,
 
1793
            timestamp, timezone, committer, revprops, revision_id,
 
1794
            lossy)
 
1795
        self.start_write_group()
 
1796
        return result
1775
1797
 
1776
1798
    def add_fallback_repository(self, repository):
1777
1799
        """Add a repository to use for looking up data not held locally.
1822
1844
            delta, new_revision_id, parents, basis_inv=basis_inv,
1823
1845
            propagate_caches=propagate_caches)
1824
1846
 
1825
 
    def add_revision(self, rev_id, rev, inv=None, config=None):
1826
 
        self._ensure_real()
1827
 
        return self._real_repository.add_revision(
1828
 
            rev_id, rev, inv=inv, config=config)
 
1847
    def add_revision(self, revision_id, rev, inv=None):
 
1848
        _mod_revision.check_not_reserved_id(revision_id)
 
1849
        key = (revision_id,)
 
1850
        # check inventory present
 
1851
        if not self.inventories.get_parent_map([key]):
 
1852
            if inv is None:
 
1853
                raise errors.WeaveRevisionNotPresent(revision_id,
 
1854
                                                     self.inventories)
 
1855
            else:
 
1856
                # yes, this is not suitable for adding with ghosts.
 
1857
                rev.inventory_sha1 = self.add_inventory(revision_id, inv,
 
1858
                                                        rev.parent_ids)
 
1859
        else:
 
1860
            rev.inventory_sha1 = self.inventories.get_sha1s([key])[key]
 
1861
        self._add_revision(rev)
 
1862
 
 
1863
    def _add_revision(self, rev):
 
1864
        if self._real_repository is not None:
 
1865
            return self._real_repository._add_revision(rev)
 
1866
        text = self._serializer.write_revision_to_string(rev)
 
1867
        key = (rev.revision_id,)
 
1868
        parents = tuple((parent,) for parent in rev.parent_ids)
 
1869
        self._write_group_tokens, missing_keys = self._get_sink().insert_stream(
 
1870
            [('revisions', [FulltextContentFactory(key, parents, None, text)])],
 
1871
            self._format, self._write_group_tokens)
1829
1872
 
1830
1873
    @needs_read_lock
1831
1874
    def get_inventory(self, revision_id):
1991
2034
        """
1992
2035
        if self._real_repository is not None:
1993
2036
            self._real_repository.refresh_data()
 
2037
        # Refresh the parents cache for this object
 
2038
        self._unstacked_provider.disable_cache()
 
2039
        self._unstacked_provider.enable_cache()
1994
2040
 
1995
2041
    def revision_ids_to_search_result(self, result_set):
1996
2042
        """Convert a set of revision ids to a graph SearchResult."""
3154
3200
        return False
3155
3201
 
3156
3202
 
3157
 
class RemoteBranchStore(config.IniFileStore):
 
3203
class RemoteBranchStore(_mod_config.IniFileStore):
3158
3204
    """Branch store which attempts to use HPSS calls to retrieve branch store.
3159
3205
 
3160
3206
    Note that this is specific to bzr-based formats.
3212
3258
    def _ensure_real(self):
3213
3259
        self.branch._ensure_real()
3214
3260
        if self._real_store is None:
3215
 
            self._real_store = config.BranchStore(self.branch)
 
3261
            self._real_store = _mod_config.BranchStore(self.branch)
3216
3262
 
3217
3263
 
3218
3264
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
3917
3963
                value = section_obj.get(name, default)
3918
3964
        except errors.UnknownSmartMethod:
3919
3965
            value = self._vfs_get_option(name, section, default)
3920
 
        for hook in config.OldConfigHooks['get']:
 
3966
        for hook in _mod_config.OldConfigHooks['get']:
3921
3967
            hook(self, name, value)
3922
3968
        return value
3923
3969
 
3925
3971
        if len(response[0]) and response[0][0] != 'ok':
3926
3972
            raise errors.UnexpectedSmartServerResponse(response)
3927
3973
        lines = response[1].read_body_bytes().splitlines()
3928
 
        conf = config.ConfigObj(lines, encoding='utf-8')
3929
 
        for hook in config.OldConfigHooks['load']:
 
3974
        conf = _mod_config.ConfigObj(lines, encoding='utf-8')
 
3975
        for hook in _mod_config.OldConfigHooks['load']:
3930
3976
            hook(self)
3931
3977
        return conf
3932
3978