@matheusbsbs / matheus-bagliano / commits / f9a2743c35
Fork 0

Windows: start_command: Support non-NULL dir in struct child_process

A caller of start_command can set the member 'dir' to a directory to request that the child process starts with that directory as CWD. The first user of this feature was added recently in eee49b6 (Teach diff --submodule and status to handle .git files in submodules). On Windows, we have been lazy and had not implemented support for this feature, yet. This fixes the shortcoming. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Apr 11, 2010 at 22:40 UTC f9a2743c3529baab6de650aa3e3eb96de9386fec
3 files changed +8 -7
compat/mingw.c
+6 -4
@@ -618,6 +618,7 @@ static int env_compare(const void *a, const void *b)
618 }
619
620 static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
621 + const char *dir,
622 int prepend_cmd, int fhin, int fhout, int fherr)
623 {
624 STARTUPINFO si;
@@ -697,7 +698,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
698
699 memset(&pi, 0, sizeof(pi));
700 ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
700 - env ? envblk.buf : NULL, NULL, &si, &pi);
701 + env ? envblk.buf : NULL, dir, &si, &pi);
702
703 if (env)
704 strbuf_release(&envblk);
@@ -714,10 +715,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
715 static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
716 int prepend_cmd)
717 {
717 - return mingw_spawnve_fd(cmd, argv, env, prepend_cmd, 0, 1, 2);
718 + return mingw_spawnve_fd(cmd, argv, env, NULL, prepend_cmd, 0, 1, 2);
719 }
720
721 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
722 + const char *dir,
723 int fhin, int fhout, int fherr)
724 {
725 pid_t pid;
@@ -740,14 +742,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
742 pid = -1;
743 }
744 else {
743 - pid = mingw_spawnve_fd(iprog, argv, env, 1,
745 + pid = mingw_spawnve_fd(iprog, argv, env, dir, 1,
746 fhin, fhout, fherr);
747 free(iprog);
748 }
749 argv[0] = argv0;
750 }
751 else
750 - pid = mingw_spawnve_fd(prog, argv, env, 0,
752 + pid = mingw_spawnve_fd(prog, argv, env, dir, 0,
753 fhin, fhout, fherr);
754 free(prog);
755 }
compat/mingw.h
+1
@@ -223,6 +223,7 @@ int mingw_utime(const char *file_name, const struct utimbuf *times);
223 #define utime mingw_utime
224
225 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
226 + const char *dir,
227 int fhin, int fhout, int fherr);
228 void mingw_execvp(const char *cmd, char *const *argv);
229 #define execvp mingw_execvp
run-command.c
+1 -3
@@ -335,8 +335,6 @@ fail_pipe:
335 else if (cmd->out > 1)
336 fhout = dup(cmd->out);
337
338 - if (cmd->dir)
339 - die("chdir in start_command() not implemented");
338 if (cmd->env)
339 env = make_augmented_environ(cmd->env);
340
@@ -346,7 +344,7 @@ fail_pipe:
344 cmd->argv = prepare_shell_cmd(cmd->argv);
345 }
346
349 - cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env,
347 + cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
348 fhin, fhout, fherr);
349 failed_errno = errno;
350 if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))