[PATCH] Fix the path problem on Windows that prevents to run hg from its own repository

Giuseppe Bilotta bilotta78 at hotpop.com
Sat Jul 2 07:54:14 CDT 2005


On Fri, 1 Jul 2005 15:02:24 -0700, Matt Mackall wrote:

> On Fri, Jul 01, 2005 at 06:17:18PM +0200, Giuseppe Bilotta wrote:
>> The attached patch solves the path problem that prevents to run hg
>> from its own repository. Under Windows, under normal circumstances,
>> the current path is searched before the site-lib path. Therefore, when
>> running a properly-installed hg from a repository containing a
>> directory named 'mercurial', hg will fail in various way. The solution
>> is to move the current path to the end of the module look-up path.
>> This is only done if the current path is present already.
> 
> This is still slightly problematic.
> 
> What if you're running Mercurial out of its working directory? I think
> you need to go a step further and not do this unless
> os.path.dirname(__file__) != os.getcwd(). 

I think I see what you mean. What about this one, instead.

---===***===---
diff -r be6233a2bfdd hg
--- a/hg	Fri Jul 01 19:49:58 2005
+++ b/hg	Sat Jul 02 14:52:28 2005
@@ -8,6 +8,12 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
+import sys, os
+cwd = os.getcwd()
+if cwd in sys.path and os.path.dirname(__file__) != cwd:
+  sys.path.remove(cwd)
+  sys.path.append(cwd)
+
 from mercurial import commands
 
 commands.run()
---===***===---

This also uses the appropriate command (.append() instead of .extend()
... sorry, I used the wrong version in the other patch ...)

-- 
Giuseppe "Oblomov" Bilotta

[W]hat country can preserve its liberties, if its rulers are not
warned from time to time that [the] people preserve the spirit of
resistance? Let them take arms...The tree of liberty must be
refreshed from time to time, with the blood of patriots and
tyrants.
	-- Thomas Jefferson, letter to Col. William S. Smith, 1787



More information about the Mercurial mailing list