~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.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:
274
274
    # check for UNC path \\HOST\path
275
275
    if win32_path.startswith('//'):
276
276
        return 'file:' + escape(win32_path)
277
 
    return ('file:///' + str(win32_path[0].upper()) + ':' +
278
 
        escape(win32_path[2:]))
 
277
    return 'file:///' + win32_path[0].upper() + ':' + escape(win32_path[2:])
279
278
 
280
279
 
281
280
local_path_to_url = _posix_local_path_to_url
371
370
    other_scheme = other[:other_first_slash]
372
371
    if base_scheme != other_scheme:
373
372
        return other
374
 
    elif sys.platform == 'win32' and base_scheme == 'file://':
375
 
        base_drive = base[base_first_slash+1:base_first_slash+3]
376
 
        other_drive = other[other_first_slash+1:other_first_slash+3]
377
 
        if base_drive != other_drive:
378
 
            return other
379
373
 
380
374
    base_path = base[base_first_slash+1:]
381
375
    other_path = other[other_first_slash+1:]
614
608
                # Otherwise take the url decoded one
615
609
                res[i] = decoded
616
610
    return u'/'.join(res)
617
 
 
618
 
 
619
 
def derive_to_location(from_location):
620
 
    """Derive a TO_LOCATION given a FROM_LOCATION.
621
 
 
622
 
    The normal case is a FROM_LOCATION of http://foo/bar => bar.
623
 
    The Right Thing for some logical destinations may differ though
624
 
    because no / may be present at all. In that case, the result is
625
 
    the full name without the scheme indicator, e.g. lp:foo-bar => foo-bar.
626
 
    This latter case also applies when a Windows drive
627
 
    is used without a path, e.g. c:foo-bar => foo-bar.
628
 
    If no /, path separator or : is found, the from_location is returned.
629
 
    """
630
 
    if from_location.find("/") >= 0 or from_location.find(os.sep) >= 0:
631
 
        return os.path.basename(from_location.rstrip("/\\"))
632
 
    else:
633
 
        sep = from_location.find(":")
634
 
        if sep > 0:
635
 
            return from_location[sep+1:]
636
 
        else:
637
 
            return from_location