[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only.

2008-01-27 Thread Johannes Schindelin

Hi,

On Sun, 27 Jan 2008, Kirill wrote:

> They may be useful if the installation is allowed for users without
> Administrator privileges.

Thanks!  Applied.

Ciao,
Dscho


[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only

2008-01-27 Thread Johannes Schindelin

Hi,

On Sun, 27 Jan 2008, Kirill wrote:

> diff --git a/systeminfo.c b/systeminfo.c
> index 08429bf..07444d6 100644
> --- a/systeminfo.c
> +++ b/systeminfo.c
> @@ -8,32 +8,45 @@ TCHAR * msys_path(void)
>   static int found_path = 0;
>   HKEY hKey;
>   LONG lRet;
> + DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> 
>   /* Only bother to get it once. */
>   if (found_path)
>   return msysPath;
>   
> - lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> + /* try to find user-specific settings first */
> + lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
>   TEXT(GIT_CHEETAH_REG_PATH),
>   0, KEY_QUERY_VALUE, &hKey);
> - 
> - if (lRet == ERROR_SUCCESS)
> - {
> - DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> - 
> + if (ERROR_SUCCESS == lRet) {
>   lRet = RegQueryValueEx(hKey,
>  TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
>  NULL, NULL,
>  (LPBYTE)msysPath,
>  &msysPathLen);
>   RegCloseKey(hKey);
> + }
> 
> - if (lRet == ERROR_SUCCESS)
> - {
> - found_path = 1;
> - return msysPath;
> + /* if current user does not have the path, try machine-wide */
> + if (ERROR_SUCCESS != lRet) {
> + lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> + TEXT(GIT_CHEETAH_REG_PATH),
> + 0, KEY_QUERY_VALUE, &hKey);
> + if (ERROR_SUCCESS == lRet) {
> + lRet = RegQueryValueEx(hKey,
> +TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> +NULL, NULL,
> +(LPBYTE)msysPath,
> +&msysPathLen);
> + RegCloseKey(hKey);
>   }
>   }
> + 
> + if (lRet == ERROR_SUCCESS)
> + {
> + found_path = 1;
> + return msysPath;
> + }
> 
>   return NULL;
>  }

Except for this part (like I said, I'd like it refactored into a helper 
function), I like your patch.

Ciao,
Dscho


[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only.

2008-01-27 Thread Johannes Schindelin

Hi,

On Sun, 27 Jan 2008, Kirill wrote:

> On Jan 25, 2008 8:54 AM, Johannes Schindelin 
> <[EMAIL PROTECTED]> wrote:
>
> > I just thought about install-user.reg.in looking awfully like 
> > install.reg (that thought occurred to me because of what I wrote in 
> > that load.reg snippet in my other mail).  So would it be possible to 
> > generate install-user.reg from install.reg instead of 
> > install-user.reg.in?
>
> Please, comment on the following patch.
> I hope you don't mind a bit of cleaning up in the install.reg.in, namely:
> - remove redundant txtfile and lnkfile keys (they're covered by the * key);
> - bring HKEY_LOCAL_MACHINE keys closer to each other.

That seems like a good cleanup to me!

> > > diff --git a/systeminfo.c b/systeminfo.c
> > > index 08429bf..07444d6 100644
> > > --- a/systeminfo.c
> > > +++ b/systeminfo.c
> > > @@ -8,32 +8,45 @@ TCHAR * msys_path(void)
> > > + /* try to find user-specific settings first */
> > > + lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
> > >   TEXT(GIT_CHEETAH_REG_PATH),
> > >   0, KEY_QUERY_VALUE, &hKey);
> > > -
> > > - if (lRet == ERROR_SUCCESS)
> > > - {
> > > - DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> > > -
> > > + if (ERROR_SUCCESS == lRet) {
> >
> > We have the same code here:
> >
> > >   lRet = RegQueryValueEx(hKey,
> > >  TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> > >  NULL, NULL,
> > >  (LPBYTE)msysPath,
> > >  &msysPathLen);
> > >   RegCloseKey(hKey);
> > > + }
> > >
> > > - if (lRet == ERROR_SUCCESS)
> > > - {
> > > - found_path = 1;
> > > - return msysPath;
> > > + /* if current user does not have the path, try machine-wide */
> > > + if (ERROR_SUCCESS != lRet) {
> > > + lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> > > + TEXT(GIT_CHEETAH_REG_PATH),
> > > + 0, KEY_QUERY_VALUE, &hKey);
> > > + if (ERROR_SUCCESS == lRet) {
> >
> > ... and here:
> >
> > > + lRet = RegQueryValueEx(hKey,
> > > +TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> > > +NULL, NULL,
> > > +(LPBYTE)msysPath,
> > > +&msysPathLen);
> > > + RegCloseKey(hKey);
> >
> > Would it not be better to check if the user key could be found, if not,
> > try the system key, and if that was not found, error out.  Otherwise
> > proceed to actually read the value.
> I had that version, but it does not work very well if:
> - there is a user key __and__
> - there is no value under that key.
> 
> So, the code essentially verifies both conditions: the key is present
> in user space and it has a readable value. If either of them is not
> met, the code goes into machine space. Makes sense?

Absolutely.  But I am a fan of the DRY principle: Don't Repeat Yourself.  
It might make sense to make a small function (maybe 
"get_msys_path_from_registry()"?), refactoring that piece of code.  That 
would serve three purposes:

- you don't repeat yourself (and therefore, future changes do not have to 
  be carried out several times),

- the code and patch are shorter (thus bugs have a harder time to hide), 
  and

- the code is more self-documenting (making it easier for others to guess 
  your intent).

Ciao,
Dscho



[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only.

2008-01-27 Thread Kirill

Dscho,

On Jan 25, 2008 8:54 AM, Johannes Schindelin <[EMAIL PROTECTED]> wrote:
> I just thought about install-user.reg.in looking awfully like install.reg
> (that thought occurred to me because of what I wrote in that load.reg
> snippet in my other mail).  So would it be possible to generate
> install-user.reg from install.reg instead of install-user.reg.in?
Please, comment on the following patch.
I hope you don't mind a bit of cleaning up in the install.reg.in, namely:
- remove redundant txtfile and lnkfile keys (they're covered by the * key);
- bring HKEY_LOCAL_MACHINE keys closer to each other.

Any way, please, comment on the following patch :)

> > diff --git a/systeminfo.c b/systeminfo.c
> > index 08429bf..07444d6 100644
> > --- a/systeminfo.c
> > +++ b/systeminfo.c
> > @@ -8,32 +8,45 @@ TCHAR * msys_path(void)
> > + /* try to find user-specific settings first */
> > + lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
> >   TEXT(GIT_CHEETAH_REG_PATH),
> >   0, KEY_QUERY_VALUE, &hKey);
> > -
> > - if (lRet == ERROR_SUCCESS)
> > - {
> > - DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> > -
> > + if (ERROR_SUCCESS == lRet) {
>
> We have the same code here:
>
> >   lRet = RegQueryValueEx(hKey,
> >  TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> >  NULL, NULL,
> >  (LPBYTE)msysPath,
> >  &msysPathLen);
> >   RegCloseKey(hKey);
> > + }
> >
> > - if (lRet == ERROR_SUCCESS)
> > - {
> > - found_path = 1;
> > - return msysPath;
> > + /* if current user does not have the path, try machine-wide */
> > + if (ERROR_SUCCESS != lRet) {
> > + lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> > + TEXT(GIT_CHEETAH_REG_PATH),
> > + 0, KEY_QUERY_VALUE, &hKey);
> > + if (ERROR_SUCCESS == lRet) {
>
> ... and here:
>
> > + lRet = RegQueryValueEx(hKey,
> > +TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> > +NULL, NULL,
> > +(LPBYTE)msysPath,
> > +&msysPathLen);
> > + RegCloseKey(hKey);
>
> Would it not be better to check if the user key could be found, if not,
> try the system key, and if that was not found, error out.  Otherwise
> proceed to actually read the value.
I had that version, but it does not work very well if:
- there is a user key __and__
- there is no value under that key.

So, the code essentially verifies both conditions: the key is present
in user space and it has a readable value. If either of them is not
met, the code goes into machine space. Makes sense?

--
Kirill.


[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only.

2008-01-25 Thread Johannes Schindelin

Hi,

On Fri, 25 Jan 2008, Kirill wrote:

> diff --git a/install-user.reg.in b/install-user.reg.in

I hope you don't mind me commenting so much on your patch, but I think 
that we are getting a good discussion.

BTW do not feel like what I say is set in stone; if you think I'm wrong, 
tell me so, and why.

I just thought about install-user.reg.in looking awfully like install.reg 
(that thought occurred to me because of what I wrote in that load.reg 
snippet in my other mail).  So would it be possible to generate 
install-user.reg from install.reg instead of install-user.reg.in?

That would serve two purposes:

- the patch would be smaller

- it would be harder to get install.reg and install-user.reg out-of-sync.

> diff --git a/systeminfo.c b/systeminfo.c
> index 08429bf..07444d6 100644
> --- a/systeminfo.c
> +++ b/systeminfo.c
> @@ -8,32 +8,45 @@ TCHAR * msys_path(void)
>   static int found_path = 0;
>   HKEY hKey;
>   LONG lRet;
> + DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> 
>   /* Only bother to get it once. */
>   if (found_path)
>   return msysPath;
>   
> - lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> + /* try to find user-specific settings first */
> + lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
>   TEXT(GIT_CHEETAH_REG_PATH),
>   0, KEY_QUERY_VALUE, &hKey);
> - 
> - if (lRet == ERROR_SUCCESS)
> - {
> - DWORD msysPathLen = MAX_PATH * sizeof(TCHAR);
> - 
> + if (ERROR_SUCCESS == lRet) {

We have the same code here:

>   lRet = RegQueryValueEx(hKey,
>  TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
>  NULL, NULL,
>  (LPBYTE)msysPath,
>  &msysPathLen);
>   RegCloseKey(hKey);
> + }
> 
> - if (lRet == ERROR_SUCCESS)
> - {
> - found_path = 1;
> - return msysPath;
> + /* if current user does not have the path, try machine-wide */
> + if (ERROR_SUCCESS != lRet) {
> + lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> + TEXT(GIT_CHEETAH_REG_PATH),
> + 0, KEY_QUERY_VALUE, &hKey);
> + if (ERROR_SUCCESS == lRet) {

... and here:

> + lRet = RegQueryValueEx(hKey,
> +TEXT(GIT_CHEETAH_REG_PATHTOMSYS),
> +NULL, NULL,
> +(LPBYTE)msysPath,
> +&msysPathLen);
> + RegCloseKey(hKey);

Would it not be better to check if the user key could be found, if not, 
try the system key, and if that was not found, error out.  Otherwise 
proceed to actually read the value.

Hmm?

Thanks,
Dscho



[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only

2008-01-25 Thread Johannes Schindelin

Hi,

On Fri, 25 Jan 2008, Kirill wrote:

> On Jan 25, 2008 6:32 AM, Johannes Schindelin 
> <[EMAIL PROTECTED]> wrote:
>
> > On Thu, 24 Jan 2008, Kirill wrote:
> >
> > > In addition, the following two might be interesting as per 
> > > "Debugging with the Shell" on MSDN:
> > >
> > > [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
> > > DesktopProcess= 1
> > >
> > > [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\
> > >  AlwaysUnloadDll]
> >
> > Could you just implement that as a follow-up patch (and not put it 
> > into this commit message)?
>
> I've removed them from this commit message, but not sure how to add them 
> as a separate patch. The problem is they are useful only for developers 
> while debugging.

Exactly.  And as we are catering for developers ATM, that should be an 
important detail.  IIUC this patch would make 89383fe8(Add a simple script 
to kill and restart explorer and task manager) obsolete?  If it does, we 
might revert that commit, mentioning that your patch is the reason.

> You don't want to add them as part of the production installation. It 
> feels weird to have yet another pair of targets, e.g. ease-debugging and 
> ease-debugging-user (the AlwaysUnloadDll works in the user space as 
> well).

How about a new target "load":

load: load.reg
regsvr32 -s $(TARGET)
regedit -s $@

load.reg: install-user.reg WINREG=HKEY_CURRENT_USER\Software\Microsoft\Windows
cp $< $@
echo '' >> $@
echo '[$(WINREG)\CurrentVersion\Explorer]' >> $@
echo '"DesktopProcess"="1"' >> $@
echo '' >> $@
echo '[$(WINREG)\CurrentVersion\Explorer\AlwaysUnloadDll]' >> $@

And a similar one for "unload"?

Ciao,
Dscho



[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only

2008-01-25 Thread Kirill

Dscho,

On Jan 25, 2008 6:32 AM, Johannes Schindelin <[EMAIL PROTECTED]> wrote:
> On Thu, 24 Jan 2008, Kirill wrote:
> > In addition, the following two might be interesting as per "Debugging
> > with the Shell" on MSDN:
> > [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
> > DesktopProcess= 1
> >
> > [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\
> >  AlwaysUnloadDll]
>
> Could you just implement that as a follow-up patch (and not put it into
> this commit message)?
I've removed them from this commit message, but not sure how to add
them as a separate patch. The problem is they are useful only for
developers while debugging. You don't want to add them as part of the
production installation. It feels weird to have yet another pair of
targets, e.g. ease-debugging and ease-debugging-user (the
AlwaysUnloadDll works in the user space as well).

--
Kirill.


[msysGit] Re: [cheetah] [PATCH] Add ability to install for the current user only

2008-01-25 Thread Johannes Schindelin

Hi,

On Thu, 24 Jan 2008, Kirill wrote:

> They may be useful if the installation is allowed for users without 
> Administrator privileges.

Nice.

> In addition, the following two might be interesting as per "Debugging
> with the Shell" on MSDN:
> [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
> DesktopProcess= 1
> 
> [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\
>  AlwaysUnloadDll]

Could you just implement that as a follow-up patch (and not put it into 
this commit message)?

> +install-user: all install-user.reg
> + regsvr32 -s git_shell_ext.dll
> + regedit -s install.reg

Certainly, you meant "install-user.reg" here, right?  It would be even 
easier if you wrote it like this:

install-user: install-user.reg all
regsvr32 -s $(TARGET)
regedit -s $<

>  install.reg: install.reg.in Makefile
>   sed < $< > $@ \
>   -e 's|@@MSYSGIT_PATH@@|$(MSYSGIT_PATH)|' \
>   -e 's|@@DLL_PATH@@|$(DLL_PATH)|'
> 
> +install-user.reg: install-user.reg.in Makefile
> + sed < $< > $@ \
> + -e 's|@@MSYSGIT_PATH@@|$(MSYSGIT_PATH)|' \
> + -e 's|@@DLL_PATH@@|$(DLL_PATH)|'

How about just unifying them?

%.reg: %.reg.in Makefile
sed < $< > $@ \
-e 's|@@MSYSGIT_PATH@@|$(MSYSGIT_PATH)|' \
-e 's|@@DLL_PATH@@|$(DLL_PATH)|'

> diff --git a/systeminfo.c b/systeminfo.c
> index 08429bf..388faf3 100644
> --- a/systeminfo.c
> +++ b/systeminfo.c
> @@ -16,6 +16,12 @@ TCHAR * msys_path(void)
>   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
>   TEXT(GIT_CHEETAH_REG_PATH),
>   0, KEY_QUERY_VALUE, &hKey);
> +
> + /* If we failed to find it in the machine-wide, try current user */
> + if (ERROR_SUCCESS != lRet)
> + lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
> + TEXT(GIT_CHEETAH_REG_PATH),
> + 0, KEY_QUERY_VALUE, &hKey);

Hmm.  I could imagine that the user-specific setting should override the 
system-wide setting, i.e. the order should be switched around...

Thanks,
Dscho