/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2008-01-04 03:12:11 UTC
  • mfrom: (3164 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080104031211-wy4uxo2j4elvip1j
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
        return cmp((self.start, self.length, self.ranges),
235
235
                   (other.start, other.length, other.ranges))
236
236
 
 
237
    def __repr__(self):
 
238
        return '%s(%r, %r, %r)' % (self.__class__.__name__,
 
239
            self.start, self.length, self.ranges)
 
240
 
237
241
 
238
242
class LateReadError(object):
239
243
    """A helper for transports which pretends to be a readable file.
339
343
        This handles things like ENOENT, ENOTDIR, EEXIST, and EACCESS
340
344
        """
341
345
        if getattr(e, 'errno', None) is not None:
342
 
            if e.errno in (errno.ENOENT, errno.ENOTDIR):
 
346
            if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
343
347
                raise errors.NoSuchFile(path, extra=e)
344
348
            # I would rather use errno.EFOO, but there doesn't seem to be
345
349
            # any matching for 267
788
792
        return offsets
789
793
 
790
794
    @staticmethod
791
 
    def _coalesce_offsets(offsets, limit, fudge_factor):
 
795
    def _coalesce_offsets(offsets, limit=0, fudge_factor=0, max_size=0):
792
796
        """Yield coalesced offsets.
793
797
 
794
798
        With a long list of neighboring requests, combine them
797
801
        Turns  [(15, 10), (25, 10)] => [(15, 20, [(0, 10), (10, 10)])]
798
802
 
799
803
        :param offsets: A list of (start, length) pairs
800
 
        :param limit: Only combine a maximum of this many pairs
801
 
                      Some transports penalize multiple reads more than
802
 
                      others, and sometimes it is better to return early.
803
 
                      0 means no limit
 
804
 
 
805
        :param limit: Only combine a maximum of this many pairs Some transports
 
806
                penalize multiple reads more than others, and sometimes it is
 
807
                better to return early.
 
808
                0 means no limit
 
809
 
804
810
        :param fudge_factor: All transports have some level of 'it is
805
811
                better to read some more data and throw it away rather 
806
812
                than seek', so collapse if we are 'close enough'
 
813
 
 
814
        :param max_size: Create coalesced offsets no bigger than this size.
 
815
                When a single offset is bigger than 'max_size', it will keep
 
816
                its size and be alone in the coalesced offset.
 
817
                0 means no maximum size.
 
818
 
807
819
        :return: yield _CoalescedOffset objects, which have members for where
808
820
                to start, how much to read, and how to split those 
809
821
                chunks back up
813
825
 
814
826
        for start, size in offsets:
815
827
            end = start + size
816
 
            if (last_end is not None 
 
828
            if (last_end is not None
817
829
                and start <= last_end + fudge_factor
818
830
                and start >= cur.start
819
 
                and (limit <= 0 or len(cur.ranges) < limit)):
 
831
                and (limit <= 0 or len(cur.ranges) < limit)
 
832
                and (max_size <= 0 or end - cur.start <= max_size)):
820
833
                cur.length = end - cur.start
821
834
                cur.ranges.append((start-cur.start, size))
822
835
            else: