comparison mercurial/ui.py @ 26064:1b1ab6ff58c4

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 07 Aug 2015 21:53:34 -0700
parents 5f2a4fc3c4fa
children cebf7e48365e
comparison
equal deleted inserted replaced
26063:d29859cfcfc2 26064:1b1ab6ff58c4
994 994
995 for name, loc in ui.configitems('paths'): 995 for name, loc in ui.configitems('paths'):
996 # No location is the same as not existing. 996 # No location is the same as not existing.
997 if not loc: 997 if not loc:
998 continue 998 continue
999
1000 # TODO ignore default-push once all consumers stop referencing it
1001 # since it is handled specifically below.
1002
999 self[name] = path(name, rawloc=loc) 1003 self[name] = path(name, rawloc=loc)
1004
1005 # Handle default-push, which is a one-off that defines the push URL for
1006 # the "default" path.
1007 defaultpush = ui.config('paths', 'default-push')
1008 if defaultpush and 'default' in self:
1009 self['default']._pushloc = defaultpush
1000 1010
1001 def getpath(self, name, default=None): 1011 def getpath(self, name, default=None):
1002 """Return a ``path`` from a string, falling back to a default. 1012 """Return a ``path`` from a string, falling back to a default.
1003 1013
1004 ``name`` can be a named path or locations. Locations are filesystem 1014 ``name`` can be a named path or locations. Locations are filesystem
1025 return None 1035 return None
1026 1036
1027 class path(object): 1037 class path(object):
1028 """Represents an individual path and its configuration.""" 1038 """Represents an individual path and its configuration."""
1029 1039
1030 def __init__(self, name, rawloc=None): 1040 def __init__(self, name, rawloc=None, pushloc=None):
1031 """Construct a path from its config options. 1041 """Construct a path from its config options.
1032 1042
1033 ``name`` is the symbolic name of the path. 1043 ``name`` is the symbolic name of the path.
1034 ``rawloc`` is the raw location, as defined in the config. 1044 ``rawloc`` is the raw location, as defined in the config.
1045 ``pushloc`` is the raw locations pushes should be made to.
1035 1046
1036 If ``name`` is not defined, we require that the location be a) a local 1047 If ``name`` is not defined, we require that the location be a) a local
1037 filesystem path with a .hg directory or b) a URL. If not, 1048 filesystem path with a .hg directory or b) a URL. If not,
1038 ``ValueError`` is raised. 1049 ``ValueError`` is raised.
1039 """ 1050 """
1051 self.branch = branch 1062 self.branch = branch
1052 1063
1053 self.name = name 1064 self.name = name
1054 self.rawloc = rawloc 1065 self.rawloc = rawloc
1055 self.loc = str(u) 1066 self.loc = str(u)
1067 self._pushloc = pushloc
1056 1068
1057 # When given a raw location but not a symbolic name, validate the 1069 # When given a raw location but not a symbolic name, validate the
1058 # location is valid. 1070 # location is valid.
1059 if (not name and not u.scheme 1071 if (not name and not u.scheme
1060 and not os.path.isdir(os.path.join(str(u), '.hg'))): 1072 and not os.path.isdir(os.path.join(str(u), '.hg'))):
1061 raise ValueError('location is not a URL or path to a local ' 1073 raise ValueError('location is not a URL or path to a local '
1062 'repo: %s' % rawloc) 1074 'repo: %s' % rawloc)
1075
1076 @property
1077 def pushloc(self):
1078 return self._pushloc or self.loc
1063 1079
1064 # we instantiate one globally shared progress bar to avoid 1080 # we instantiate one globally shared progress bar to avoid
1065 # competing progress bars when multiple UI objects get created 1081 # competing progress bars when multiple UI objects get created
1066 _progresssingleton = None 1082 _progresssingleton = None
1067 1083