summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-01-02 15:35:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-01-17 22:05:42 (GMT)
commita2a20b0d5c97580497da37814c8b62114ce25f81 (patch)
tree50953f3b08e8bd58be960b56293efd1f6600b309 /sequencer.c
parentac191470c7dba893388f4038851d68fea2094cea (diff)
downloadgit-a2a20b0d5c97580497da37814c8b62114ce25f81.zip
git-a2a20b0d5c97580497da37814c8b62114ce25f81.tar.gz
git-a2a20b0d5c97580497da37814c8b62114ce25f81.tar.bz2
sequencer: update reading author-script
Rather than abusing a strbuf to come up with an environment block, let's just use the argv_array structure which serves the same purpose much better. While at it, rename the function to reflect the fact that it does not really care exactly what environment variables are defined in said file. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/sequencer.c b/sequencer.c
index 41f80ea..7acd0bd 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -544,18 +544,17 @@ missing_author:
}
/*
- * Read the author-script file into an environment block, ready for use in
- * run_command(), that can be free()d afterwards.
+ * Read a list of environment variable assignments (such as the author-script
+ * file) into an environment block. Returns -1 on error, 0 otherwise.
*/
-static char **read_author_script(void)
+static int read_env_script(struct argv_array *env)
{
struct strbuf script = STRBUF_INIT;
int i, count = 0;
- char *p, *p2, **env;
- size_t env_size;
+ char *p, *p2;
if (strbuf_read_file(&script, rebase_path_author_script(), 256) <= 0)
- return NULL;
+ return -1;
for (p = script.buf; *p; p++)
if (skip_prefix(p, "'\\\\''", (const char **)&p2))
@@ -567,19 +566,12 @@ static char **read_author_script(void)
count++;
}
- env_size = (count + 1) * sizeof(*env);
- strbuf_grow(&script, env_size);
- memmove(script.buf + env_size, script.buf, script.len);
- p = script.buf + env_size;
- env = (char **)strbuf_detach(&script, NULL);
-
- for (i = 0; i < count; i++) {
- env[i] = p;
+ for (i = 0, p = script.buf; i < count; i++) {
+ argv_array_push(env, p);
p += strlen(p) + 1;
}
- env[count] = NULL;
- return env;
+ return 0;
}
static const char staged_changes_advice[] =
@@ -612,14 +604,12 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
int allow_empty, int edit, int amend,
int cleanup_commit_message)
{
- char **env = NULL;
- struct argv_array array;
+ struct argv_array env = ARGV_ARRAY_INIT, array;
int rc;
const char *value;
if (is_rebase_i(opts)) {
- env = read_author_script();
- if (!env) {
+ if (!read_env_script(&env)) {
const char *gpg_opt = gpg_sign_opt_quoted(opts);
return error(_(staged_changes_advice),
@@ -655,9 +645,9 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
argv_array_push(&array, "--allow-empty-message");
rc = run_command_v_opt_cd_env(array.argv, RUN_GIT_CMD, NULL,
- (const char *const *)env);
+ (const char *const *)env.argv);
argv_array_clear(&array);
- free(env);
+ argv_array_clear(&env);
return rc;
}