Skip to content

Commit

Permalink
Windows: start_command: Support non-NULL dir in struct child_process
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Apr 11, 2010
1 parent eee49b6 commit f9a2743
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ static int env_compare(const void *a, const void *b)
}

static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
const char *dir,
int prepend_cmd, int fhin, int fhout, int fherr)
{
STARTUPINFO si;
Expand Down Expand Up @@ -697,7 +698,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,

memset(&pi, 0, sizeof(pi));
ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
env ? envblk.buf : NULL, NULL, &si, &pi);
env ? envblk.buf : NULL, dir, &si, &pi);

if (env)
strbuf_release(&envblk);
Expand All @@ -714,10 +715,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
int prepend_cmd)
{
return mingw_spawnve_fd(cmd, argv, env, prepend_cmd, 0, 1, 2);
return mingw_spawnve_fd(cmd, argv, env, NULL, prepend_cmd, 0, 1, 2);
}

pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
const char *dir,
int fhin, int fhout, int fherr)
{
pid_t pid;
Expand All @@ -740,14 +742,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
pid = -1;
}
else {
pid = mingw_spawnve_fd(iprog, argv, env, 1,
pid = mingw_spawnve_fd(iprog, argv, env, dir, 1,
fhin, fhout, fherr);
free(iprog);
}
argv[0] = argv0;
}
else
pid = mingw_spawnve_fd(prog, argv, env, 0,
pid = mingw_spawnve_fd(prog, argv, env, dir, 0,
fhin, fhout, fherr);
free(prog);
}
Expand Down
1 change: 1 addition & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ int mingw_utime(const char *file_name, const struct utimbuf *times);
#define utime mingw_utime

pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
const char *dir,
int fhin, int fhout, int fherr);
void mingw_execvp(const char *cmd, char *const *argv);
#define execvp mingw_execvp
Expand Down
4 changes: 1 addition & 3 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ int start_command(struct child_process *cmd)
else if (cmd->out > 1)
fhout = dup(cmd->out);

if (cmd->dir)
die("chdir in start_command() not implemented");
if (cmd->env)
env = make_augmented_environ(cmd->env);

Expand All @@ -346,7 +344,7 @@ int start_command(struct child_process *cmd)
cmd->argv = prepare_shell_cmd(cmd->argv);
}

cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env,
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
fhin, fhout, fherr);
failed_errno = errno;
if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
Expand Down

0 comments on commit f9a2743

Please sign in to comment.