~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Patch Queue Manager
  • Date: 2011-11-22 13:52:59 UTC
  • mfrom: (6270.1.23 hpss-branch-store)
  • Revision ID: pqm@pqm.ubuntu.com-20111122135259-dfjq13wb2z4ndbh6
(jelmer) Support HPSS calls for config stacks of remote branches and
 bzrdirs. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
        _mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
334
334
 
335
335
 
 
336
class RemoteControlStore(config.IniFileStore):
 
337
    """Control store which attempts to use HPSS calls to retrieve control store.
 
338
 
 
339
    Note that this is specific to bzr-based formats.
 
340
    """
 
341
 
 
342
    def __init__(self, bzrdir):
 
343
        super(RemoteControlStore, self).__init__()
 
344
        self.bzrdir = bzrdir
 
345
        self._real_store = None
 
346
 
 
347
    def lock_write(self, token=None):
 
348
        self._ensure_real()
 
349
        return self._real_store.lock_write(token)
 
350
 
 
351
    def unlock(self):
 
352
        self._ensure_real()
 
353
        return self._real_store.unlock()
 
354
 
 
355
    @needs_write_lock
 
356
    def save(self):
 
357
        # We need to be able to override the undecorated implementation
 
358
        self.save_without_locking()
 
359
 
 
360
    def save_without_locking(self):
 
361
        super(RemoteControlStore, self).save()
 
362
 
 
363
    def _ensure_real(self):
 
364
        self.bzrdir._ensure_real()
 
365
        if self._real_store is None:
 
366
            self._real_store = config.ControlStore(self.bzrdir)
 
367
 
 
368
    def external_url(self):
 
369
        return self.bzrdir.user_url
 
370
 
 
371
    def _load_content(self):
 
372
        medium = self.bzrdir._client._medium
 
373
        path = self.bzrdir._path_for_remote_call(self.bzrdir._client)
 
374
        try:
 
375
            response, handler = self.bzrdir._call_expecting_body(
 
376
                'BzrDir.get_config_file', path)
 
377
        except errors.UnknownSmartMethod:
 
378
            self._ensure_real()
 
379
            return self._real_store._load_content()
 
380
        if len(response) and response[0] != 'ok':
 
381
            raise errors.UnexpectedSmartServerResponse(response)
 
382
        return handler.read_body_bytes()
 
383
 
 
384
    def _save_content(self, content):
 
385
        # FIXME JRV 2011-11-22: Ideally this should use a
 
386
        # HPSS call too, but at the moment it is not possible
 
387
        # to write lock control directories.
 
388
        self._ensure_real()
 
389
        return self._real_store._save_content(content)
 
390
 
 
391
 
336
392
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
337
393
    """Control directory on a remote server, accessed via bzr:// or similar."""
338
394
 
718
774
    def _get_config(self):
719
775
        return RemoteBzrDirConfig(self)
720
776
 
 
777
    def _get_config_store(self):
 
778
        return RemoteControlStore(self)
 
779
 
721
780
 
722
781
class RemoteRepositoryFormat(vf_repository.VersionedFileRepositoryFormat):
723
782
    """Format for repositories accessed over a _SmartClient.
2538
2597
                return True
2539
2598
        return False
2540
2599
 
 
2600
 
 
2601
class RemoteBranchStore(config.IniFileStore):
 
2602
    """Branch store which attempts to use HPSS calls to retrieve branch store.
 
2603
 
 
2604
    Note that this is specific to bzr-based formats.
 
2605
    """
 
2606
 
 
2607
    def __init__(self, branch):
 
2608
        super(RemoteBranchStore, self).__init__()
 
2609
        self.branch = branch
 
2610
        self.id = "branch"
 
2611
        self._real_store = None
 
2612
 
 
2613
    def lock_write(self, token=None):
 
2614
        return self.branch.lock_write(token)
 
2615
 
 
2616
    def unlock(self):
 
2617
        return self.branch.unlock()
 
2618
 
 
2619
    @needs_write_lock
 
2620
    def save(self):
 
2621
        # We need to be able to override the undecorated implementation
 
2622
        self.save_without_locking()
 
2623
 
 
2624
    def save_without_locking(self):
 
2625
        super(RemoteBranchStore, self).save()
 
2626
 
 
2627
    def external_url(self):
 
2628
        return self.branch.user_url
 
2629
 
 
2630
    def _load_content(self):
 
2631
        path = self.branch._remote_path()
 
2632
        try:
 
2633
            response, handler = self.branch._call_expecting_body(
 
2634
                'Branch.get_config_file', path)
 
2635
        except errors.UnknownSmartMethod:
 
2636
            self._ensure_real()
 
2637
            return self._real_store._load_content()
 
2638
        if len(response) and response[0] != 'ok':
 
2639
            raise errors.UnexpectedSmartServerResponse(response)
 
2640
        return handler.read_body_bytes()
 
2641
 
 
2642
    def _save_content(self, content):
 
2643
        path = self.branch._remote_path()
 
2644
        try:
 
2645
            response, handler = self.branch._call_with_body_bytes_expecting_body(
 
2646
                'Branch.put_config_file', (path,
 
2647
                    self.branch._lock_token, self.branch._repo_lock_token),
 
2648
                content)
 
2649
        except errors.UnknownSmartMethod:
 
2650
            self._ensure_real()
 
2651
            return self._real_store._save_content(content)
 
2652
        handler.cancel_read_body()
 
2653
        if response != ('ok', ):
 
2654
            raise errors.UnexpectedSmartServerResponse(response)
 
2655
 
 
2656
    def _ensure_real(self):
 
2657
        self.branch._ensure_real()
 
2658
        if self._real_store is None:
 
2659
            self._real_store = config.BranchStore(self.branch)
 
2660
 
 
2661
 
2541
2662
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2542
2663
    """Branch stored on a server accessed by HPSS RPC.
2543
2664
 
2632
2753
    def _get_config(self):
2633
2754
        return RemoteBranchConfig(self)
2634
2755
 
 
2756
    def _get_config_store(self):
 
2757
        return RemoteBranchStore(self)
 
2758
 
2635
2759
    def _get_real_transport(self):
2636
2760
        # if we try vfs access, return the real branch's vfs transport
2637
2761
        self._ensure_real()