~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Server-side branch related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import errors
 
20
from bzrlib import (
 
21
    bencode,
 
22
    errors,
 
23
    )
21
24
from bzrlib.bzrdir import BzrDir
22
25
from bzrlib.smart.request import (
23
26
    FailedSmartServerResponse,
103
106
        return SuccessfulSmartServerResponse((bytes,))
104
107
 
105
108
 
 
109
class SmartServerBranchSetTagsBytes(SmartServerLockedBranchRequest):
 
110
 
 
111
    def __init__(self, backing_transport, root_client_path='/', jail_root=None):
 
112
        SmartServerLockedBranchRequest.__init__(
 
113
            self, backing_transport, root_client_path, jail_root)
 
114
        self.locked = False
 
115
        
 
116
    def do_with_locked_branch(self, branch):
 
117
        """Call _set_tags_bytes for a branch.
 
118
 
 
119
        New in 1.18.
 
120
        """
 
121
        # We need to keep this branch locked until we get a body with the tags
 
122
        # bytes.
 
123
        self.branch = branch
 
124
        self.branch.lock_write()
 
125
        self.locked = True
 
126
 
 
127
    def do_body(self, bytes):
 
128
        self.branch._set_tags_bytes(bytes)
 
129
        return SuccessfulSmartServerResponse(())
 
130
 
 
131
    def do_end(self):
 
132
        # TODO: this request shouldn't have to do this housekeeping manually.
 
133
        # Some of this logic probably belongs in a base class.
 
134
        if not self.locked:
 
135
            # We never acquired the branch successfully in the first place, so
 
136
            # there's nothing more to do.
 
137
            return
 
138
        try:
 
139
            return SmartServerLockedBranchRequest.do_end(self)
 
140
        finally:
 
141
            # Only try unlocking if we locked successfully in the first place
 
142
            self.branch.unlock()
 
143
 
 
144
 
106
145
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
107
146
 
108
147
    def do_with_branch(self, branch):
158
197
        return SuccessfulSmartServerResponse(())
159
198
 
160
199
 
 
200
class SmartServerBranchRequestSetConfigOptionDict(SmartServerLockedBranchRequest):
 
201
    """Set an option in the branch configuration.
 
202
    
 
203
    New in 2.2.
 
204
    """
 
205
 
 
206
    def do_with_locked_branch(self, branch, value_dict, name, section):
 
207
        utf8_dict = bencode.bdecode(value_dict)
 
208
        value_dict = {}
 
209
        for key, value in utf8_dict.items():
 
210
            value_dict[key.decode('utf8')] = value.decode('utf8')
 
211
        if not section:
 
212
            section = None
 
213
        branch._get_config().set_option(value_dict, name, section)
 
214
        return SuccessfulSmartServerResponse(())
 
215
 
 
216
 
161
217
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
162
218
 
163
219
    def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
256
312
        if repo_token == '':
257
313
            repo_token = None
258
314
        try:
259
 
            repo_token = branch.repository.lock_write(token=repo_token)
 
315
            repo_token = branch.repository.lock_write(
 
316
                token=repo_token).repository_token
260
317
            try:
261
 
                branch_token = branch.lock_write(token=branch_token)
 
318
                branch_token = branch.lock_write(
 
319
                    token=branch_token).branch_token
262
320
            finally:
263
321
                # this leaves the repository with 1 lock
264
322
                branch.repository.unlock()