~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    osutils,
34
34
    urlutils,
35
35
    symbol_versioning,
36
 
    transport,
37
36
    )
38
37
from bzrlib.trace import mutter
39
 
from bzrlib.transport import LateReadError
40
38
""")
41
39
 
42
40
from bzrlib.transport import Transport, Server
66
64
        super(LocalTransport, self).__init__(base)
67
65
        self._local_base = urlutils.local_path_from_url(base)
68
66
 
 
67
    def should_cache(self):
 
68
        return False
 
69
 
69
70
    def clone(self, offset=None):
70
71
        """Return a new LocalTransport with root at self.base + offset
71
72
        Because the local filesystem does not require a connection, 
125
126
            abspath = u'.'
126
127
 
127
128
        return urlutils.file_relpath(
128
 
            urlutils.strip_trailing_slash(self.base),
 
129
            urlutils.strip_trailing_slash(self.base), 
129
130
            urlutils.strip_trailing_slash(abspath))
130
131
 
131
132
    def has(self, relpath):
136
137
 
137
138
        :param relpath: The relative path to the file
138
139
        """
139
 
        canonical_url = self.abspath(relpath)
140
 
        if canonical_url in transport._file_streams:
141
 
            transport._file_streams[canonical_url].flush()
142
140
        try:
143
141
            path = self._abspath(relpath)
144
142
            return open(path, 'rb')
145
143
        except (IOError, OSError),e:
146
 
            if e.errno == errno.EISDIR:
147
 
                return LateReadError(relpath)
148
144
            self._translate_error(e, path)
149
145
 
150
146
    def put_file(self, relpath, f, mode=None):
164
160
        except (IOError, OSError),e:
165
161
            self._translate_error(e, path)
166
162
        try:
167
 
            length = self._pump(f, fp)
 
163
            self._pump(f, fp)
168
164
            fp.commit()
169
165
        finally:
170
166
            fp.close()
171
 
        return length
172
167
 
173
168
    def put_bytes(self, relpath, bytes, mode=None):
174
169
        """Copy the string into the location.
303
298
        """Create a directory at the given path."""
304
299
        self._mkdir(self._abspath(relpath), mode=mode)
305
300
 
306
 
    def open_write_stream(self, relpath, mode=None):
307
 
        """See Transport.open_write_stream."""
308
 
        # initialise the file
309
 
        self.put_bytes_non_atomic(relpath, "", mode=mode)
310
 
        abspath = self._abspath(relpath)
311
 
        handle = open(abspath, 'wb')
312
 
        if mode is not None:
313
 
            self._check_mode_and_size(abspath, handle.fileno(), mode)
314
 
        transport._file_streams[self.abspath(relpath)] = handle
315
 
        return transport.FileFileStream(self, relpath, handle)
316
 
 
317
301
    def _get_append_file(self, relpath, mode=None):
318
302
        """Call os.open() for the given relpath"""
319
303
        file_abspath = self._abspath(relpath)
406
390
        except (IOError, OSError),e:
407
391
            self._translate_error(e, path)
408
392
 
409
 
    def external_url(self):
410
 
        """See bzrlib.transport.Transport.external_url."""
411
 
        # File URL's are externally usable.
412
 
        return self.base
413
 
 
414
393
    def copy_to(self, relpaths, other, mode=None, pb=None):
415
394
        """Copy a set of entries from self into another Transport.
416
395