[PATCH V2] debuginstall: display warning when multiple installs are present (issue4141)

Prasoon Shukla prasoon92.iitr at gmail.com
Sat Jan 11 03:24:28 CST 2014


Version 2 of patch for issue 4141<http://bz.selenic.com/show_bug.cgi?id=4141>.
Tests have not been added because there is not support for multiline
matching. The problems mentioned by Matt have been fixed. Please see this
thread for details:
http://mercurial.808500.n3.nabble.com/PATCH-debuginstall-display-warning-when-multiple-installs-are-present-issue4141-td4006273.html

# HG changeset patch
# User Prasoon Shukla <prasoon92.iitr at gmail.com>
# Date 1389431301 -19800
# Node ID 5d9942f43bee3e6c04c24cba24b340be5d7ab6cc
# Parent  d2704c48f4176d8cd6f21d33500820d44763585c
debuginstall: display warning when multiple installs are present (issue4141)

If multiple installations of hg are present, a warning is displayed along
with all the installs.

diff -r d2704c48f417 -r 5d9942f43bee mercurial/commands.py
--- a/mercurial/commands.py Fri Nov 15 23:28:43 2013 -0500
+++ b/mercurial/commands.py Sat Jan 11 14:38:21 2014 +0530
@@ -8,7 +8,7 @@
 from node import hex, bin, nullid, nullrev, short
 from lock import release
 from i18n import _
-import os, re, difflib, time, tempfile, errno
+import os, sys, re, difflib, time, tempfile, errno
 import hg, scmutil, util, revlog, copies, error, bookmarks
 import patch, help, encoding, templatekw, discovery
 import archival, changegroup, cmdutil, hbisect
@@ -2047,6 +2047,16 @@

     problems = 0

+    # installations
+    installs = util.findhgexe()
+    if not installs:
+        ui.warn(_("warning! no file named hg found in path"))
+    else:
+        ui.status(_("checking hg path (%s)...\n" % sys.argv[0]))
+        if len(installs) > 1:
+            ui.warn(_("warning! multiple installs of hg detected:\n
 %s...\n"
+                      % '\n  '.join(installs)))
+
     # encoding
     ui.status(_("checking encoding (%s)...\n") % encoding.encoding)
     try:
diff -r d2704c48f417 -r 5d9942f43bee mercurial/util.py
--- a/mercurial/util.py Fri Nov 15 23:28:43 2013 -0500
+++ b/mercurial/util.py Sat Jan 11 14:38:21 2014 +0530
@@ -14,7 +14,7 @@
 """

 from i18n import _
-import error, osutil, encoding
+import error, osutil, encoding, glob
 import errno, re, shutil, sys, tempfile, traceback
 import os, time, datetime, calendar, textwrap, signal, collections
 import imp, socket, urllib
@@ -1983,3 +1983,27 @@
         self._hooks.sort(key=lambda x: x[0])
         for source, hook in self._hooks:
             hook(*args)
+
+def findhgexe(path=None):
+    '''Find all executables containing `hg` in `path`.'''
+
+    matches = []
+
+    if (sys.platform == 'win32' or os.name == 'os2'):
+        exe = 'hg*.exe'
+    else:
+        exe = 'hg*'
+
+    if path is None:
+        path = os.environ['PATH']
+    paths = path.split(os.pathsep)
+
+    for p in paths:
+        matchstr = p + '/' + exe
+        allexes = [f for f in glob.glob(matchstr) if
+                   all(['ssh' not in f, 'web' not in f, 'editor' not in
f])]
+        for f in allexes:
+            if os.path.isfile(f):
+                matches.append(f)
+
+    return matches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140111/ca1e9528/attachment.html>


More information about the Mercurial-devel mailing list