mercurial/httpconnection.py
branchstable
changeset 15005 4a43e23b8c55
parent 14430 c864f5e743ef
child 15025 0593e8f81c71
equal deleted inserted replaced
15004:d06b9c55ddab 15005:4a43e23b8c55
    70         if setting in ('username', 'cert', 'key'):
    70         if setting in ('username', 'cert', 'key'):
    71             val = util.expandpath(val)
    71             val = util.expandpath(val)
    72         gdict[setting] = val
    72         gdict[setting] = val
    73 
    73 
    74     # Find the best match
    74     # Find the best match
       
    75     uri = util.url(uri)
       
    76     user = uri.user
       
    77     uri.user = uri.password = None
       
    78     uri = str(uri)
    75     scheme, hostpath = uri.split('://', 1)
    79     scheme, hostpath = uri.split('://', 1)
       
    80     bestuser = None
    76     bestlen = 0
    81     bestlen = 0
    77     bestauth = None
    82     bestauth = None
    78     for group, auth in config.iteritems():
    83     for group, auth in config.iteritems():
       
    84         if user and user != auth.get('username', user):
       
    85             # If a username was set in the URI, the entry username
       
    86             # must either match it or be unset
       
    87             continue
    79         prefix = auth.get('prefix')
    88         prefix = auth.get('prefix')
    80         if not prefix:
    89         if not prefix:
    81             continue
    90             continue
    82         p = prefix.split('://', 1)
    91         p = prefix.split('://', 1)
    83         if len(p) > 1:
    92         if len(p) > 1:
    84             schemes, prefix = [p[0]], p[1]
    93             schemes, prefix = [p[0]], p[1]
    85         else:
    94         else:
    86             schemes = (auth.get('schemes') or 'https').split()
    95             schemes = (auth.get('schemes') or 'https').split()
    87         if (prefix == '*' or hostpath.startswith(prefix)) and \
    96         if (prefix == '*' or hostpath.startswith(prefix)) and \
    88             len(prefix) > bestlen and scheme in schemes:
    97             (len(prefix) > bestlen or (len(prefix) == bestlen and \
       
    98                 not bestuser and 'username' in auth)) \
       
    99              and scheme in schemes:
    89             bestlen = len(prefix)
   100             bestlen = len(prefix)
    90             bestauth = group, auth
   101             bestauth = group, auth
       
   102             bestuser = auth.get('username')
       
   103             if user and not bestuser:
       
   104                 auth['username'] = user
    91     return bestauth
   105     return bestauth
    92 
   106 
    93 # Mercurial (at least until we can remove the old codepath) requires
   107 # Mercurial (at least until we can remove the old codepath) requires
    94 # that the http response object be sufficiently file-like, so we
   108 # that the http response object be sufficiently file-like, so we
    95 # provide a close() method here.
   109 # provide a close() method here.