Comments
Patch
@@ -528,11 +528,8 @@ class ui(object):
return user
def expandpath(self, loc, default=None):
"""Return repository location relative to cwd or from [paths]"""
- if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
- return loc
-
if loc == 'default-push':
p = self.paths.getpath(loc, default=True)
elif loc == 'default':
p = self.paths.getpath(loc)
@@ -957,15 +954,19 @@ class paths(dict):
self[name] = path(name, rawloc=loc)
def getpath(self, name, default=False):
- """Return a ``path`` for the specified name, falling back to a default.
+ """Return a ``path`` from a string.
+
+ Arguments can be named paths (from the config) or locations. Locations
+ are URIs or filesystem paths that are directories having ``.hg``
+ directories.
If ``default`` is True, we attempt to resolve the default path.
If ``default`` is the string ``push``, we attempt to resolve the
default push path.
- Returns ``None`` if a path could not be found.
+ Returns ``None`` if a path could not be resolved.
"""
try:
return self[name]
except KeyError:
@@ -983,18 +984,39 @@ class paths(dict):
return self['default']
except KeyError:
pass
+ try:
+ return path(name)
+ except ValueError:
+ pass
+
return None
class path(object):
"""Represents an individual path and its configuration."""
def __init__(self, name, rawloc=None):
"""Construct a path from its config options.
- ``name`` is the symbolic name of the path.
+ ``name`` is the symbolic name of the path or location.
``rawloc`` is the raw location, as defined in the config.
+
+ When ``rawloc`` isn't defined, we assume ``name`` is the location.
+ In this form, we require that the location be a local filesystem
+ path to a known repository or a URL. If not, ``ValueError`` is
+ raised.
"""
+ if name and not rawloc:
+ if util.hasscheme(name):
+ self.name = None
+ self.loc = name
+ elif os.path.isdir(os.path.join(name, '.hg')):
+ self.name = name
+ self.loc = name
+ else:
+ raise ValueError('location is not a URL or path to a local '
+ 'repo: %s' % name)
+ return
+
self.name = name
- # We'll do more intelligent things with rawloc in the future.
self.loc = rawloc