def segmentspan(revlog, revs, deltainfo=None):
    """Get the byte span of a segment of revisions

    revs is a sorted array of revision numbers

    >>> revlog = _testrevlog([
    ...  5,  #0
    ...  10, #1
    ...  12, #2
    ...  12, #3 (empty)
    ...  17, #4
    ... ])

    >>> segmentspan(revlog, [0, 1, 2, 3, 4])
    17
    >>> segmentspan(revlog, [0, 4])
    17
    >>> segmentspan(revlog, [3, 4])
    5
    >>> segmentspan(revlog, [1, 2, 3,])
    7
    >>> segmentspan(revlog, [1, 3])
    7
    """
    if not revs:
        return 0
    if deltainfo is not None and len(revlog) <= revs[-1]:
        if len(revs) == 1:
            return deltainfo.deltalen
        offset = revlog.end(len(revlog) - 1)
        end = deltainfo.deltalen + offset
    else:
        end = revlog.end(revs[-1])
    return end - revlog.start(revs[0])