[PATCH 1 of 6 path intent] ui: add an intent to expandpath

Gregory Szorc gregory.szorc at gmail.com
Mon Sep 29 00:30:21 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1411967336 25200
#      Sun Sep 28 22:08:56 2014 -0700
# Node ID 2f06625fe4d502f43294e9087d9a83398a36fe9f
# Parent  4109cc16279ef0e04dc70e7f4c9ab7415e6a22d3
ui: add an intent to expandpath

This patch adds an optional named argument to ui.expandpath() that
defines the intended use of a repository.

The impetus behind this patch is to allow extensions to provide
more advanced and dynamic repository lookup functionality. For
example, there exists an extension at Mozilla which automagically
defines common repository URLs for the many Firefox repositories.
We want read operations hitting read-only slaves over HTTP(S) and
write operations hitting the master over SSH. Today, we have to
use separate names for separate URLs, which increases cognitive
burden and sometimes results in accidental use of the wrong repo.
We desire built-in hg operations to automagically use the URL for
the task at hand. This change and subsequent additions to define
the intent parameter will enable this through monkeypatching
ui.expandpath().

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -496,10 +496,18 @@ class ui(object):
         if not self.verbose:
             user = util.shortuser(user)
         return user
 
-    def expandpath(self, loc, default=None):
-        """Return repository location relative to cwd or from [paths]"""
+    def expandpath(self, loc, default=None, intent=None):
+        '''Return repository location relative to cwd or from [paths].
+
+        loc is the location to expand. It can be a URL, filesystem path,
+        or symbolic name.
+
+        intent is a string describing the intended use of this repo. It is
+        intended for extensions so that extensions may do things like return
+        different URLs for push versus pull.
+        '''
         if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
             return loc
 
         path = self.config('paths', loc)


More information about the Mercurial-devel mailing list