[PATCH 1 of 2] ui: capture push location on path instances

Gregory Szorc gregory.szorc at gmail.com
Sat Aug 22 17:03:55 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1439009614 25200
#      Fri Aug 07 21:53:34 2015 -0700
# Node ID 1ff7d2d55194e14ff90094009e75d0beb6719232
# Parent  d75d57eea9af5d62a24356f129aa2d774ec32c03
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
@@ -995,10 +995,20 @@ class paths(dict):
         for name, loc in ui.configitems('paths'):
             # 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.
 
         ``name`` can be a named path or locations. Locations are filesystem
@@ -1026,13 +1036,14 @@ 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,
         ``ValueError`` is raised.
@@ -1052,16 +1063,21 @@ 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.
         if (not name and not u.scheme
             and not os.path.isdir(os.path.join(str(u), '.hg'))):
             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
 


More information about the Mercurial-devel mailing list