Commits

Angel Ezquerra  committed 61d851e

Add "localhost" special server path, which matches any source on the local machine.

  • Participants
  • Parent commits 90bd1ba

Comments (0)

Files changed (2)

 Configuration Examples
 ----------------------
 
+The following are several configuration examples that will show how to
+configure this extension.
+
+Pay especial attention to configuration #3 below , which is probably the most useful
+base configuration on a typical corporate environment:
+
 1. Accept all project configurations from all servers, without confirmation:
 
 The least safe configuration for this extension is one that accepts
 all project settings from all servers without any confirmation prompt:
 
+servers = *
 include = *
-servers = *
 confirm = False
 
-2. Accept all project configurations from the default pull sources:
+2. Accept all project configurations from a central repository server:
+
+Note that with this configuration clones of local clones will _not_ get the projrc file!
+
+servers = http://mycentralserver/*
+include = *
+confirm = False
+
+3. Accept all project configurations from a central repo and from local repositories:
+
+This is probably the most useful base configuration of this extension.
+It ensures that you'll only get the projrc file from a central server
+(e.g. your company's mercurial server) but that you will also propagate it
+to clones of local clones.
+
+servers = http://mycentralserver/*, localhost
+include = *
+confirm = False
+
+4. Accept all project configurations from a central repo and from local repositories,
+but prompt to accept configuration changes:
+
+This is a safer variation of the previos configuration. The difference is that the
+user will get a confirmation prompt whenever the projrc file changes.
+
+servers = http://mycentralserver/*, localhost
+include = *
+
+5. Accept all project configurations from the default pull sources:
 
 This makes sure that the projrc file is transferred when pulling from
 the default path, which is usually the one that we cloned from.
 Note that you won't get the projrc file when cloning. You'll get it
 when pulling for the first time.
 
+servers = default
 include = *
-servers = default
 confirm = False
 
-3. Accept all project configurations except the [hooks] section from
+6. Accept all project configurations except the [hooks] section from
 the default pull sources:
 
+servers = default
 exclude = hooks
-servers = default
 confirm = False
 
-4. Accept all project configurations except the [hooks] section from
-the default pull sources, but prompt to accept configuration changes:
-
-exclude = hooks
-servers = default
-
-5. Only get the commit hook from the project configuration file, from
+7. Only get the commit hook from the project configuration file, from
 the central repository, but prompt to accept configuration changes:
 
+servers = http://mycentralserver/*
 include = hooks.commit
-servers = http://mercurial/*
 
 
 Sponsoring
     # .hg/hgrc, file in $HGRCPATH, or an included file
     return HGRC
 
+def isfilepath(pth):
+    """True if a path is not an http, https or ssh path"""
+    return (pth[1:2] == ':') or (pth[0:1] in '\\/')
+
+def islocalpath(pth):
+    """Return true for local paths
+
+    A local path is a file path that is not a network path or a URL address whose server is locahost or 127.0.0.1
+    """
+    if isfilepath(pth):
+        return (pth[1:2] not in '\\/')
+    else:
+        try:
+            protocol, pth = pth.split('//')
+            return pth.split('/')[0] in ('localhost', '127.0.0.1')
+        except ValueError:
+            return False
+    return False
+
 def findpatternmatch(searchtext, patternlist):
     """Find whether a string matches any of the glob patterns on a pattern list
 
 
     for n, server in enumerate(serverlist):
         server = ui.expandpath(server)
-        localpath = (server[1:2] == ':') or (server[0:1] in '\\/')
-        if localpath:
+        filepath = isfilepath(server)
+        if filepath:
             serverlist[n] = os.path.normcase(util.normpath(server))
         else:
             serverlist[n] = server.lower()
         remotepath = other.url()
 
     if '*' not in projrcserverset and \
-            not findpatternmatch(remotepath, projrcserverset)[0]:
+            not findpatternmatch(remotepath, projrcserverset)[0] and \
+            not ("localhost" in projrcserverset and islocalpath(remotepath)):
         # The pull source is not on the projrc server list
         # Note that we keep any existing local projrc file, which may have been
         # transferred from another valid server