~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-06 14:01:16 UTC
  • mto: (4241.10.1 bzr.1.14)
  • mto: This revision was merged to the branch mainline in revision 4267.
  • Revision ID: v.ladeuil+lp@free.fr-20090406140116-zkbvjtaxfhbql4l4
Fix unicode related OSX failures.

* bzrlib/tests/test_export.py: 
Fix imports.

* bzrlib/tests/blackbox/test_export.py:
(TestExport.test_tar_export_unicode,
TestExport.test_zip_export_unicode): Use a less problematic
unicode char for OSX.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 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 (
21
 
    bencode,
22
 
    errors,
23
 
    )
 
20
from bzrlib import errors
24
21
from bzrlib.bzrdir import BzrDir
25
22
from bzrlib.smart.request import (
26
23
    FailedSmartServerResponse,
106
103
        return SuccessfulSmartServerResponse((bytes,))
107
104
 
108
105
 
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
 
 
145
106
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
146
107
 
147
108
    def do_with_branch(self, branch):
187
148
            return FailedSmartServerResponse(('TipChangeRejected', msg))
188
149
 
189
150
 
190
 
class SmartServerBranchRequestSetConfigOption(SmartServerLockedBranchRequest):
191
 
    """Set an option in the branch configuration."""
192
 
 
193
 
    def do_with_locked_branch(self, branch, value, name, section):
194
 
        if not section:
195
 
            section = None
196
 
        branch._get_config().set_option(value.decode('utf8'), name, section)
197
 
        return SuccessfulSmartServerResponse(())
198
 
 
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
 
 
217
151
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
218
152
 
219
153
    def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
293
227
        return SuccessfulSmartServerResponse(('ok',))
294
228
 
295
229
 
296
 
class SmartServerBranchRequestSetParentLocation(SmartServerLockedBranchRequest):
297
 
    """Set the parent location for a branch.
298
 
    
299
 
    Takes a location to set, which must be utf8 encoded.
300
 
    """
301
 
 
302
 
    def do_with_locked_branch(self, branch, location):
303
 
        branch._set_parent_location(location)
304
 
        return SuccessfulSmartServerResponse(())
305
 
 
306
 
 
307
230
class SmartServerBranchRequestLockWrite(SmartServerBranchRequest):
308
231
 
309
232
    def do_with_branch(self, branch, branch_token='', repo_token=''):
312
235
        if repo_token == '':
313
236
            repo_token = None
314
237
        try:
315
 
            repo_token = branch.repository.lock_write(
316
 
                token=repo_token).repository_token
 
238
            repo_token = branch.repository.lock_write(token=repo_token)
317
239
            try:
318
 
                branch_token = branch.lock_write(
319
 
                    token=branch_token).branch_token
 
240
                branch_token = branch.lock_write(token=branch_token)
320
241
            finally:
321
242
                # this leaves the repository with 1 lock
322
243
                branch.repository.unlock()