commit: extract cleanup_mode functions to sequencer
Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
94ca361bfb
commit
f29cd8620d
|
@ -1172,24 +1172,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
|
||||||
die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
|
die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
|
||||||
if (argc == 0 && (also || (only && !amend && !allow_empty)))
|
if (argc == 0 && (also || (only && !amend && !allow_empty)))
|
||||||
die(_("No paths with --include/--only does not make sense."));
|
die(_("No paths with --include/--only does not make sense."));
|
||||||
if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
|
cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor);
|
||||||
cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_ALL :
|
|
||||||
COMMIT_MSG_CLEANUP_SPACE;
|
|
||||||
else if (!strcmp(cleanup_arg, "verbatim"))
|
|
||||||
cleanup_mode = COMMIT_MSG_CLEANUP_NONE;
|
|
||||||
else if (!strcmp(cleanup_arg, "whitespace"))
|
|
||||||
cleanup_mode = COMMIT_MSG_CLEANUP_SPACE;
|
|
||||||
else if (!strcmp(cleanup_arg, "strip"))
|
|
||||||
cleanup_mode = COMMIT_MSG_CLEANUP_ALL;
|
|
||||||
else if (!strcmp(cleanup_arg, "scissors"))
|
|
||||||
cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :
|
|
||||||
COMMIT_MSG_CLEANUP_SPACE;
|
|
||||||
/*
|
|
||||||
* Please update _git_commit() in git-completion.bash when you
|
|
||||||
* add new options.
|
|
||||||
*/
|
|
||||||
else
|
|
||||||
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
|
||||||
|
|
||||||
handle_untracked_files_arg(s);
|
handle_untracked_files_arg(s);
|
||||||
|
|
||||||
|
@ -1626,11 +1609,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||||
die(_("could not read commit message: %s"), strerror(saved_errno));
|
die(_("could not read commit message: %s"), strerror(saved_errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose || /* Truncate the message just before the diff, if any. */
|
cleanup_message(&sb, cleanup_mode, verbose);
|
||||||
cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
|
|
||||||
strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len));
|
|
||||||
if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE)
|
|
||||||
strbuf_stripspace(&sb, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
|
|
||||||
|
|
||||||
if (message_is_empty(&sb, cleanup_mode) && !allow_empty_message) {
|
if (message_is_empty(&sb, cleanup_mode) && !allow_empty_message) {
|
||||||
rollback_index_files();
|
rollback_index_files();
|
||||||
|
|
29
sequencer.c
29
sequencer.c
|
@ -516,6 +516,25 @@ static int fast_forward_to(struct repository *r,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
|
||||||
|
int use_editor)
|
||||||
|
{
|
||||||
|
if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
|
||||||
|
return use_editor ? COMMIT_MSG_CLEANUP_ALL :
|
||||||
|
COMMIT_MSG_CLEANUP_SPACE;
|
||||||
|
else if (!strcmp(cleanup_arg, "verbatim"))
|
||||||
|
return COMMIT_MSG_CLEANUP_NONE;
|
||||||
|
else if (!strcmp(cleanup_arg, "whitespace"))
|
||||||
|
return COMMIT_MSG_CLEANUP_SPACE;
|
||||||
|
else if (!strcmp(cleanup_arg, "strip"))
|
||||||
|
return COMMIT_MSG_CLEANUP_ALL;
|
||||||
|
else if (!strcmp(cleanup_arg, "scissors"))
|
||||||
|
return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :
|
||||||
|
COMMIT_MSG_CLEANUP_SPACE;
|
||||||
|
else
|
||||||
|
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
||||||
|
}
|
||||||
|
|
||||||
void append_conflicts_hint(struct index_state *istate,
|
void append_conflicts_hint(struct index_state *istate,
|
||||||
struct strbuf *msgbuf)
|
struct strbuf *msgbuf)
|
||||||
{
|
{
|
||||||
|
@ -1018,6 +1037,16 @@ static int rest_is_empty(const struct strbuf *sb, int start)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanup_message(struct strbuf *msgbuf,
|
||||||
|
enum commit_msg_cleanup_mode cleanup_mode, int verbose)
|
||||||
|
{
|
||||||
|
if (verbose || /* Truncate the message just before the diff, if any. */
|
||||||
|
cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
|
||||||
|
strbuf_setlen(msgbuf, wt_status_locate_end(msgbuf->buf, msgbuf->len));
|
||||||
|
if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE)
|
||||||
|
strbuf_stripspace(msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find out if the message in the strbuf contains only whitespace and
|
* Find out if the message in the strbuf contains only whitespace and
|
||||||
* Signed-off-by lines.
|
* Signed-off-by lines.
|
||||||
|
|
|
@ -117,6 +117,12 @@ int rearrange_squash(struct repository *r);
|
||||||
void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
|
void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
|
||||||
|
|
||||||
void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);
|
void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);
|
||||||
|
enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
|
||||||
|
int use_editor);
|
||||||
|
|
||||||
|
void cleanup_message(struct strbuf *msgbuf,
|
||||||
|
enum commit_msg_cleanup_mode cleanup_mode, int verbose);
|
||||||
|
|
||||||
int message_is_empty(const struct strbuf *sb,
|
int message_is_empty(const struct strbuf *sb,
|
||||||
enum commit_msg_cleanup_mode cleanup_mode);
|
enum commit_msg_cleanup_mode cleanup_mode);
|
||||||
int template_untouched(const struct strbuf *sb, const char *template_file,
|
int template_untouched(const struct strbuf *sb, const char *template_file,
|
||||||
|
|
Loading…
Reference in New Issue