~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-17 21:19:56 UTC
  • mfrom: (1997.1.6 bind-does-not-push-or-pull)
  • Revision ID: pqm@pqm.ubuntu.com-20060917211956-6e30d07da410fd1a
(Robert Collins) Change the Branch bind method to just bind rather than binding and pushing (fixes #43744 and #39542)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
so this is primarily useful for testing.
21
21
"""
22
22
 
23
 
from copy import copy
24
23
import os
25
24
import errno
26
25
import re
27
 
from stat import *
 
26
from stat import S_IFREG, S_IFDIR
28
27
from cStringIO import StringIO
 
28
import warnings
29
29
 
30
30
from bzrlib.errors import TransportError, NoSuchFile, FileExists, LockError
31
31
from bzrlib.trace import mutter
58
58
        if url[-1] != '/':
59
59
            url = url + '/'
60
60
        super(MemoryTransport, self).__init__(url)
61
 
        self._cwd = url[url.find(':') + 3:]
 
61
        split = url.find(':') + 3
 
62
        self._scheme = url[:split]
 
63
        self._cwd = url[split:]
62
64
        # dictionaries from absolute path to file mode
63
65
        self._dirs = {'/':None}
64
66
        self._files = {}
66
68
 
67
69
    def clone(self, offset=None):
68
70
        """See Transport.clone()."""
69
 
        if offset is None or offset == '':
70
 
            return copy(self)
71
 
        segments = offset.split('/')
72
 
        cwdsegments = self._cwd.split('/')[:-1]
73
 
        while len(segments):
74
 
            segment = segments.pop(0)
75
 
            if segment == '.':
76
 
                continue
77
 
            if segment == '..':
78
 
                if len(cwdsegments) > 1:
79
 
                    cwdsegments.pop()
80
 
                continue
81
 
            cwdsegments.append(segment)
82
 
        url = self.base[:self.base.find(':') + 3] + '/'.join(cwdsegments) + '/'
 
71
        path = self._combine_paths(self._cwd, offset)
 
72
        if len(path) == 0 or path[-1] != '/':
 
73
            path += '/'
 
74
        url = self._scheme + path
83
75
        result = MemoryTransport(url)
84
76
        result._dirs = self._dirs
85
77
        result._files = self._files
97
89
        else:
98
90
            return temp_t.base[:-1]
99
91
 
100
 
    def append(self, relpath, f, mode=None):
101
 
        """See Transport.append()."""
 
92
    def append_file(self, relpath, f, mode=None):
 
93
        """See Transport.append_file()."""
102
94
        _abspath = self._abspath(relpath)
103
95
        self._check_parent(_abspath)
104
96
        orig_content, orig_mode = self._files.get(_abspath, ("", None))
116
108
    def has(self, relpath):
117
109
        """See Transport.has()."""
118
110
        _abspath = self._abspath(relpath)
119
 
        return _abspath in self._files or _abspath in self._dirs
 
111
        return (_abspath in self._files) or (_abspath in self._dirs)
120
112
 
121
113
    def delete(self, relpath):
122
114
        """See Transport.delete()."""
132
124
            raise NoSuchFile(relpath)
133
125
        return StringIO(self._files[_abspath][0])
134
126
 
135
 
    def put(self, relpath, f, mode=None):
136
 
        """See Transport.put()."""
 
127
    def put_file(self, relpath, f, mode=None):
 
128
        """See Transport.put_file()."""
137
129
        _abspath = self._abspath(relpath)
138
130
        self._check_parent(_abspath)
139
131
        self._files[_abspath] = (f.read(), mode)
153
145
    def iter_files_recursive(self):
154
146
        for file in self._files:
155
147
            if file.startswith(self._cwd):
156
 
                yield file[len(self._cwd):]
 
148
                yield urlutils.escape(file[len(self._cwd):])
157
149
    
158
150
    def list_dir(self, relpath):
159
151
        """See Transport.list_dir()."""
172
164
                len(path) > len(_abspath) and
173
165
                path[len(_abspath)] == '/'):
174
166
                result.append(path[len(_abspath) + 1:])
175
 
        return result
 
167
        return map(urlutils.escape, result)
176
168
 
177
169
    def rename(self, rel_from, rel_to):
178
170
        """Rename a file or directory; fail if the destination exists"""
235
227
        relpath = urlutils.unescape(relpath)
236
228
        if relpath.find('..') != -1:
237
229
            raise AssertionError('relpath contains ..')
 
230
        if relpath == '':
 
231
            return '/'
 
232
        if relpath[0] == '/':
 
233
            return relpath
238
234
        if relpath == '.':
239
235
            if (self._cwd == '/'):
240
236
                return self._cwd
260
256
    def __del__(self):
261
257
        # Should this warn, or actually try to cleanup?
262
258
        if self.transport:
263
 
            warn("MemoryLock %r not explicitly unlocked" % (self.path,))
 
259
            warnings.warn("MemoryLock %r not explicitly unlocked" % (self.path,))
264
260
            self.unlock()
265
261
 
266
262
    def unlock(self):