<div dir="ltr">Version 2 of patch for <a href="http://bz.selenic.com/show_bug.cgi?id=4141">issue 4141</a>. 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: <a href="http://mercurial.808500.n3.nabble.com/PATCH-debuginstall-display-warning-when-multiple-installs-are-present-issue4141-td4006273.html">http://mercurial.808500.n3.nabble.com/PATCH-debuginstall-display-warning-when-multiple-installs-are-present-issue4141-td4006273.html</a><div>
<br></div><div><div># HG changeset patch</div><div># User Prasoon Shukla <<a href="mailto:prasoon92.iitr@gmail.com">prasoon92.iitr@gmail.com</a>></div><div># Date 1389431301 -19800</div><div># Node ID 5d9942f43bee3e6c04c24cba24b340be5d7ab6cc</div>
<div># Parent  d2704c48f4176d8cd6f21d33500820d44763585c</div><div>debuginstall: display warning when multiple installs are present (issue4141)</div><div><br></div><div>If multiple installations of hg are present, a warning is displayed along</div>
<div>with all the installs.</div><div><br></div><div>diff -r d2704c48f417 -r 5d9942f43bee mercurial/commands.py</div><div>--- a/mercurial/commands.py<span class="" style="white-space:pre">  </span>Fri Nov 15 23:28:43 2013 -0500</div>
<div>+++ b/mercurial/commands.py<span class="" style="white-space:pre"> </span>Sat Jan 11 14:38:21 2014 +0530</div><div>@@ -8,7 +8,7 @@</div><div> from node import hex, bin, nullid, nullrev, short</div><div> from lock import release</div>
<div> from i18n import _</div><div>-import os, re, difflib, time, tempfile, errno</div><div>+import os, sys, re, difflib, time, tempfile, errno</div><div> import hg, scmutil, util, revlog, copies, error, bookmarks</div><div>
 import patch, help, encoding, templatekw, discovery</div><div> import archival, changegroup, cmdutil, hbisect</div><div>@@ -2047,6 +2047,16 @@</div><div> </div><div>     problems = 0</div><div> </div><div>+    # installations</div>
<div>+    installs = util.findhgexe()</div><div>+    if not installs:</div><div>+        ui.warn(_("warning! no file named hg found in path"))</div><div>+    else:</div><div>+        ui.status(_("checking hg path (%s)...\n" % sys.argv[0]))</div>
<div>+        if len(installs) > 1:</div><div>+            ui.warn(_("warning! multiple installs of hg detected:\n  %s...\n"</div><div>+                      % '\n  '.join(installs)))</div><div>+</div>
<div>     # encoding</div><div>     ui.status(_("checking encoding (%s)...\n") % encoding.encoding)</div><div>     try:</div><div>diff -r d2704c48f417 -r 5d9942f43bee mercurial/util.py</div><div>--- a/mercurial/util.py<span class="" style="white-space:pre">     </span>Fri Nov 15 23:28:43 2013 -0500</div>
<div>+++ b/mercurial/util.py<span class="" style="white-space:pre">     </span>Sat Jan 11 14:38:21 2014 +0530</div><div>@@ -14,7 +14,7 @@</div><div> """</div><div> </div><div> from i18n import _</div><div>-import error, osutil, encoding</div>
<div>+import error, osutil, encoding, glob</div><div> import errno, re, shutil, sys, tempfile, traceback</div><div> import os, time, datetime, calendar, textwrap, signal, collections</div><div> import imp, socket, urllib</div>
<div>@@ -1983,3 +1983,27 @@</div><div>         self._hooks.sort(key=lambda x: x[0])</div><div>         for source, hook in self._hooks:</div><div>             hook(*args)</div><div>+</div><div>+def findhgexe(path=None):</div>
<div>+    '''Find all executables containing `hg` in `path`.'''</div><div>+</div><div>+    matches = []</div><div>+</div><div>+    if (sys.platform == 'win32' or <a href="http://os.name">os.name</a> == 'os2'):</div>
<div>+        exe = 'hg*.exe'</div><div>+    else:</div><div>+        exe = 'hg*'</div><div>+</div><div>+    if path is None:</div><div>+        path = os.environ['PATH']</div><div>+    paths = path.split(os.pathsep)</div>
<div>+</div><div>+    for p in paths:</div><div>+        matchstr = p + '/' + exe</div><div>+        allexes = [f for f in glob.glob(matchstr) if</div><div>+                   all(['ssh' not in f, 'web' not in f, 'editor' not in f])]</div>
<div>+        for f in allexes:</div><div>+            if os.path.isfile(f):</div><div>+                matches.append(f)</div><div>+</div><div>+    return matches</div></div></div>