builtin-am: implement --rebasing mode
Since3041c32
(am: --rebasing, 2008-03-04), git-am.sh supported the --rebasing option, which is used internally by git-rebase to tell git-am that it is being used for its purpose. It would create the empty file $state_dir/rebasing to help "completion" scripts tell if the ongoing operation is am or rebase. As of0fbb95d
(am: don't call mailinfo if $rebasing, 2012-06-26), --rebasing also implies --3way as well. Sincea1549e1
(am: return control to caller, for housekeeping, 2013-05-12), git-am.sh would only clean up the state directory when it is not --rebasing, instead deferring cleanup to git-rebase.sh. Re-implement the above in builtin/am.c. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
30
builtin/am.c
30
builtin/am.c
@ -89,6 +89,7 @@ struct am_state {
|
|||||||
int quiet;
|
int quiet;
|
||||||
int signoff;
|
int signoff;
|
||||||
const char *resolvemsg;
|
const char *resolvemsg;
|
||||||
|
int rebasing;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,6 +365,8 @@ static void am_load(struct am_state *state)
|
|||||||
read_state_file(&sb, state, "sign", 1);
|
read_state_file(&sb, state, "sign", 1);
|
||||||
state->signoff = !strcmp(sb.buf, "t");
|
state->signoff = !strcmp(sb.buf, "t");
|
||||||
|
|
||||||
|
state->rebasing = !!file_exists(am_path(state, "rebasing"));
|
||||||
|
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,18 +545,29 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
|
|||||||
die(_("Failed to split patches."));
|
die(_("Failed to split patches."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->rebasing)
|
||||||
|
state->threeway = 1;
|
||||||
|
|
||||||
write_file(am_path(state, "threeway"), 1, state->threeway ? "t" : "f");
|
write_file(am_path(state, "threeway"), 1, state->threeway ? "t" : "f");
|
||||||
|
|
||||||
write_file(am_path(state, "quiet"), 1, state->quiet ? "t" : "f");
|
write_file(am_path(state, "quiet"), 1, state->quiet ? "t" : "f");
|
||||||
|
|
||||||
write_file(am_path(state, "sign"), 1, state->signoff ? "t" : "f");
|
write_file(am_path(state, "sign"), 1, state->signoff ? "t" : "f");
|
||||||
|
|
||||||
|
if (state->rebasing)
|
||||||
|
write_file(am_path(state, "rebasing"), 1, "%s", "");
|
||||||
|
else
|
||||||
|
write_file(am_path(state, "applying"), 1, "%s", "");
|
||||||
|
|
||||||
if (!get_sha1("HEAD", curr_head)) {
|
if (!get_sha1("HEAD", curr_head)) {
|
||||||
write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(curr_head));
|
write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(curr_head));
|
||||||
update_ref("am", "ORIG_HEAD", curr_head, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
|
if (!state->rebasing)
|
||||||
|
update_ref("am", "ORIG_HEAD", curr_head, NULL, 0,
|
||||||
|
UPDATE_REFS_DIE_ON_ERR);
|
||||||
} else {
|
} else {
|
||||||
write_file(am_path(state, "abort-safety"), 1, "%s", "");
|
write_file(am_path(state, "abort-safety"), 1, "%s", "");
|
||||||
delete_ref("ORIG_HEAD", NULL, 0);
|
if (!state->rebasing)
|
||||||
|
delete_ref("ORIG_HEAD", NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1054,8 +1068,14 @@ next:
|
|||||||
am_next(state);
|
am_next(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
am_destroy(state);
|
/*
|
||||||
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
|
* In rebasing mode, it's up to the caller to take care of
|
||||||
|
* housekeeping.
|
||||||
|
*/
|
||||||
|
if (!state->rebasing) {
|
||||||
|
am_destroy(state);
|
||||||
|
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1325,6 +1345,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_CMDMODE(0, "abort", &resume,
|
OPT_CMDMODE(0, "abort", &resume,
|
||||||
N_("restore the original branch and abort the patching operation."),
|
N_("restore the original branch and abort the patching operation."),
|
||||||
RESUME_ABORT),
|
RESUME_ABORT),
|
||||||
|
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
|
||||||
|
N_("(internal use for git-rebase)")),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user