RFC: Alternative for exemaker

Adrian Buehlmann adrian at cadifra.com
Sun Jun 24 01:50:17 CDT 2012


On 2012-06-24 01:25, Adrian Buehlmann wrote:
> On 2012-06-23 14:23, Mads Kiilerich wrote:
>> Andrei Polushin wrote, On 06/23/2012 01:24 PM:
>>>   2) It assumes the script name is the same as .exe name, but
>>>      without the .exe extension (.py extension is not appended)
>>
>> Do everything on windows always do The Right Thing if both a hg.exe and 
>> hg.py is present? Is there no such thing as custom extension handlers 
>> and custom priorities? I wonder if it would be more stable if X.exe 
>> looked for something like X_exe.py .
> 
> I've been thinking about this a bit.
> 
> Andrei is interested to have the hg.exe look for the plain hg.
> 
> Mads and I are interested in using hg.exe for the testsuite, where we
> have a problem (to some extent) if there is a hg file, so we rename hg
> to hg.py before running the testsuite and expect the hg.py to be called
> by the hg.exe.
> 
> I think Mads' X_exe.py idea is probably also a good one, although I
> don't particularly like the name. But I don't feel strongly about it, so
> I could live with hg_exe.py. But I propose we use the name:
> 
>   hgexe.py
> 
> That is, for the testsuite we rename the hg file to hgexe.py.
> 
> To also accomodate for the use case of Andrei, the hg.exe could first
> see if there is a hg file and use that if it's there (in the same dir as
> hg.exe). If it isn't there, it should require and use hgexe.py instead
> (in the same dir as the hg.exe).
> 
> But we can surely implement any other scheme as well. Just tell me what
> you need and I'll do it.

I just did some quick experiment:

diff --git a/hg.c b/hg.c
--- a/hg.c
+++ b/hg.c
@@ -36,10 +36,21 @@
 	int i;
 	int n;
 	char **pyargv;
+	WIN32_FIND_DATA fdata;
+	HANDLE hfind;
 
 	GetModuleFileName(NULL, scriptname, sizeof(scriptname));
 	PathRemoveFileSpec(scriptname);
-	strcat_s(scriptname, sizeof(scriptname), "\\hg.py");
+	strcat_s(scriptname, sizeof(scriptname), "\\hg");
+
+	hfind = FindFirstFile(scriptname, &fdata);
+	if (hfind != INVALID_HANDLE_VALUE) {
+		/* scriptname exits, close handle */
+		FindClose(hfind);
+	} else {
+		/* hg file isn't there, take hgexe.py */
+		strcat_s(scriptname, sizeof(scriptname), "exe.py");
+	}
 
 	/* 
 	Only add the scriptname to the args, if it's not already there. It may


Seems to work nicely so far.

FindFirstFile is known to be pretty fast for checking file existence (I've
used it in TortoiseHg's shell extension), so I assume there wouldn't be much
of a noticeable speed penalty. But I haven't measured (yet).


More information about the Mercurial-devel mailing list