Hi,
On Fri, 8 Feb 2008, Kirill wrote:
> Now, because our environment does not have git.exe or wish.exe in PATH,
> it's harder to start wish.exe, so we start git.exe hidden. Given that we
> will need other ways to start Git, a new module - exec.[ch] - is
> created.
I'd just leave that out.
> diff --git a/exec.c b/exec.c
> new file mode 100644
> index 0000000..4d519cc
> --- /dev/null
> +++ b/exec.c
> @@ -0,0 +1,76 @@
> +#include <windows.h>
> +#include <stdio.h>
> +#include "debug.h"
> +#include "systeminfo.h"
> +#include "exec.h"
> +
> +char *env_for_git()
> +{
> + static char *environment;
> +
> + /*
> + * if we can't find path to msys in the registry, return NULL and
> + * the CreateProcess will copy the environment for us
> + */
> + if (!environment && msys_path()) {
> + char *old = GetEnvironmentStrings();
> + size_t space = 0, path_index = -1, name_len = 0, len2;
> +
> + while (old[space]) {
> + /* if it's PATH variable (could be Path= too!) */
> + if (!strnicmp(old + space, "PATH=", 5)) {
> + path_index = space;
> + name_len = 5;
> + }
> +
> + while (old[space])
> + space++;
> + space++; /* skip var-terminating NULL */
> + }
> +
> + if (path_index == -1)
> + path_index = space;
> +
> + environment = (char *)malloc(space +
> + 2 * strlen(msys_path()) + 32);
You don't need to cast to "(char *)". It is common practice to cast (void
*) to any pointer implicitly.
> +
> + /* copy the block up to the equal sign of PATH var */
> + memcpy(environment, old, path_index);
> + /* insert new segments of the PATH */
> + len2 = sprintf(environment + path_index,
> + "PATH=%s\\bin;%s\\mingw\\bin%s",
> + msys_path(), msys_path(), name_len ? ";" : "");
> + /* append original value of PATH and variables after it */
> + memcpy(environment + path_index + len2,
> + old + path_index + name_len,
> + space + 1 - path_index - name_len);
> +
> + FreeEnvironmentStrings(old);
> + }
> +
> + return environment;
> +}
Nicely done. (I take it that you can use an environment NULL for a
default, when there is no msys_path()?)
> diff --git a/menu.c b/menu.c
> index c6a5a55..97811fa 100644
> --- a/menu.c
> +++ b/menu.c
> @@ -123,8 +103,7 @@ static STDMETHODIMP invoke_command(void *p,
> const char *wd;
> DWORD dwAttr, fa;
>
> - adjust_path_for_git(msysPath);
> - wsprintf(command, TEXT("wish.exe \"%s/bin/git-gui\""),
> + wsprintf(command, TEXT("\"%s\\bin\\git.exe\" gui"),
Good! But does that not mean that we do not even have to adjust the PATH?
Thanks,
Dscho