# HG changeset patch # User Gregory Szorc # Date 2015-08-08 04:53:34 # Node ID 1b1ab6ff58c48cc5dd6acd63bcbf8069fe10b21a # Parent d29859cfcfc26c0a22b347dbbffe4308944135f3 ui: capture push location on path instances Currently, we treat "default" and "default-push" as separate paths, even though they are the same logical entity but with different paths for different operations. Because they are the same entity and because we will eventually be implementing an official mechanism for declaring push URLs for paths, we establish a "pushloc" attribute on path instances. We populate this attribute on the "default" path with the "default-push" value, if present. This will enable consumers stop referencing "default-push" which will make their code simpler. diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -996,8 +996,18 @@ class paths(dict): # No location is the same as not existing. if not loc: continue + + # TODO ignore default-push once all consumers stop referencing it + # since it is handled specifically below. + self[name] = path(name, rawloc=loc) + # Handle default-push, which is a one-off that defines the push URL for + # the "default" path. + defaultpush = ui.config('paths', 'default-push') + if defaultpush and 'default' in self: + self['default']._pushloc = defaultpush + def getpath(self, name, default=None): """Return a ``path`` from a string, falling back to a default. @@ -1027,11 +1037,12 @@ class paths(dict): class path(object): """Represents an individual path and its configuration.""" - def __init__(self, name, rawloc=None): + def __init__(self, name, rawloc=None, pushloc=None): """Construct a path from its config options. ``name`` is the symbolic name of the path. ``rawloc`` is the raw location, as defined in the config. + ``pushloc`` is the raw locations pushes should be made to. If ``name`` is not defined, we require that the location be a) a local filesystem path with a .hg directory or b) a URL. If not, @@ -1053,6 +1064,7 @@ class path(object): self.name = name self.rawloc = rawloc self.loc = str(u) + self._pushloc = pushloc # When given a raw location but not a symbolic name, validate the # location is valid. @@ -1061,6 +1073,10 @@ class path(object): raise ValueError('location is not a URL or path to a local ' 'repo: %s' % rawloc) + @property + def pushloc(self): + return self._pushloc or self.loc + # we instantiate one globally shared progress bar to avoid # competing progress bars when multiple UI objects get created _progresssingleton = None