sq_quote_argv and add_to_string rework with strbuf's.

* sq_quote_buf is made public, and works on a strbuf.
* sq_quote_argv also works on a strbuf.
* make sq_quote_argv take a "maxlen" argument to check the buffer won't grow
  too big.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pierre Habouzit
2007-09-20 00:42:13 +02:00
committed by Junio C Hamano
parent 663af3422a
commit 7a33bcbe80
6 changed files with 86 additions and 137 deletions

View File

@ -577,16 +577,13 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
if (pid < 0)
die("unable to fork");
if (!pid) {
char command[MAX_CMD_LEN];
char *posn = command;
int size = MAX_CMD_LEN;
int of = 0;
struct strbuf cmd;
of |= add_to_string(&posn, &size, prog, 0);
of |= add_to_string(&posn, &size, " ", 0);
of |= add_to_string(&posn, &size, path, 1);
if (of)
strbuf_init(&cmd, MAX_CMD_LEN);
strbuf_addstr(&cmd, prog);
strbuf_addch(&cmd, ' ');
sq_quote_buf(&cmd, path);
if (cmd.len >= MAX_CMD_LEN)
die("command line too long");
dup2(pipefd[1][0], 0);
@ -606,10 +603,10 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
ssh_basename++;
if (!port)
execlp(ssh, ssh_basename, host, command, NULL);
execlp(ssh, ssh_basename, host, cmd.buf, NULL);
else
execlp(ssh, ssh_basename, "-p", port, host,
command, NULL);
cmd.buf, NULL);
}
else {
unsetenv(ALTERNATE_DB_ENVIRONMENT);
@ -618,7 +615,7 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
unsetenv(GIT_WORK_TREE_ENVIRONMENT);
unsetenv(GRAFT_ENVIRONMENT);
unsetenv(INDEX_ENVIRONMENT);
execlp("sh", "sh", "-c", command, NULL);
execlp("sh", "sh", "-c", cmd.buf, NULL);
}
die("exec failed");
}