1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-28 04:36:10 +02:00

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>
This commit is contained in:
Johannes Schindelin 2017-01-02 16:35:25 +01:00 committed by Junio C Hamano
parent ac191470c7
commit a2a20b0d5c
2 changed files with 28 additions and 22 deletions

View File

@ -544,18 +544,17 @@ static int write_author_script(const char *message)
}
/*
* 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;
}

View File

@ -237,6 +237,22 @@ test_expect_success 'retain authorship' '
git show HEAD | grep "^Author: Twerp Snog"
'
test_expect_success 'retain authorship w/ conflicts' '
git reset --hard twerp &&
test_commit a conflict a conflict-a &&
git reset --hard twerp &&
GIT_AUTHOR_NAME=AttributeMe \
test_commit b conflict b conflict-b &&
set_fake_editor &&
test_must_fail git rebase -i conflict-a &&
echo resolved >conflict &&
git add conflict &&
git rebase --continue &&
test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
git show >out &&
grep AttributeMe out
'
test_expect_success 'squash' '
git reset --hard twerp &&
echo B > file7 &&